Partial import processing
This commit is contained in:
@@ -4,7 +4,9 @@ import {connect} from 'react-redux';
|
||||
import './SkynetImport.css'
|
||||
import Box from '../../components/UI/Box/Box';
|
||||
import Button from '../../components/UI/Button/Button';
|
||||
import {displaySkynetImport} from '../../redux/actions/skynet_actions';
|
||||
import {
|
||||
displaySkynetImport, importSkylinks
|
||||
} from '../../redux/actions/skynet_actions';
|
||||
import {
|
||||
notifyError,
|
||||
notifyInfo
|
||||
@@ -15,6 +17,7 @@ const mapDispatchToProps = dispatch => {
|
||||
displaySkynetImport: display => dispatch(displaySkynetImport(display)),
|
||||
notifyInfo: msg => dispatch(notifyInfo('Import Syntax', msg)),
|
||||
notifyError: msg => dispatch(notifyError(msg)),
|
||||
importSkylinks: (version, jsonArray) => dispatch(importSkylinks(version, jsonArray)),
|
||||
}
|
||||
};
|
||||
|
||||
@@ -55,12 +58,12 @@ export default connect(null, mapDispatchToProps)(class extends Component {
|
||||
|
||||
processNext = () => {
|
||||
const items = this.state.import_list.split('\n');
|
||||
let jsonItems = [];
|
||||
let importsArray = [];
|
||||
try {
|
||||
for (let item of items) {
|
||||
item = item.trim();
|
||||
if (item.startsWith('[')) {
|
||||
jsonItems = JSON.parse(this.state.import_list.trim());
|
||||
importsArray = JSON.parse(this.state.import_list.trim());
|
||||
break;
|
||||
} else if (item.indexOf('=') >= 0) {
|
||||
const parts = item.split(',')
|
||||
@@ -83,19 +86,19 @@ export default connect(null, mapDispatchToProps)(class extends Component {
|
||||
if (!importItem.skylink) {
|
||||
throw new Error('Invalid syntax for import: directory="",skylink="",token=""');
|
||||
}
|
||||
jsonItems.push(importItem);
|
||||
importsArray.push(importItem);
|
||||
} else if (item.length > 0) {
|
||||
jsonItems.push({
|
||||
importsArray.push({
|
||||
directory: '/',
|
||||
skylink: item,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (jsonItems.length === 0) {
|
||||
if (importsArray.length === 0) {
|
||||
throw new Error('Nothing to import');
|
||||
}
|
||||
console.log(jsonItems);
|
||||
this.props.importSkylinks(this.props.version, importsArray);
|
||||
} catch (e) {
|
||||
this.props.notifyError(e);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user