{
+ return {
+ AppBusy: state.common.AppBusy,
+ };
+};
const mapDispatchToProps = dispatch => {
return {
displaySkynetImport: display => dispatch(displaySkynetImport(display)),
- notifyInfo: msg => dispatch(notifyInfo('Import Syntax', msg)),
+ notifyApplicationBusy: busy => dispatch(notifyApplicationBusy(busy, true)),
notifyError: msg => dispatch(notifyError(msg)),
- importSkylinks: (version, jsonArray) => dispatch(importSkylinks(version, jsonArray)),
+ notifyInfo: msg => dispatch(notifyInfo('Import Syntax', msg)),
}
};
-export default connect(null, mapDispatchToProps)(class extends Component {
+export default connect(mapStateToProps, mapDispatchToProps)(class extends IPCContainer {
state = {
- import_list: '',
+ import_text: '',
+ imports_array: [],
+ second_stage: false,
};
+ componentDidMount() {
+ this.setRequestHandler(Constants.IPC_Import_Skylinks_Reply, this.onImportSkylinksReply);
+ }
+
+ componentWillUnmount() {
+ super.componentWillUnmount();
+ }
+
displaySyntax = () => {
const msg = '!alternate!To import Skylinks into the root directory, list each Skylink on a new line:\n' +
' AACeCiD6WQG6DzDcCdIu3cFPSxMUMoQPx46NYSyijNMKUA\n' +
' AACyjmDGoHqY7mTaxi-rkpnKUJGZK1B4UhrF74Nv6tY6Cg\n' +
'\n' +
- 'To import Skylinks to new or existing directories, use the following syntax:\n' +
+ 'To import Skylinks into new or existing directories, use the following syntax:\n' +
' directory="/my/sub/dir",skylink="AACeCiD6WQG6DzDcCdIu3cFPSxMUMoQPx46NYSyijNMKUA"\n' +
' directory="/my/sub/dir2",skylink="AACyjmDGoHqY7mTaxi-rkpnKUJGZK1B4UhrF74Nv6tY6Cg"\n' +
'\n' +
@@ -40,7 +57,7 @@ export default connect(null, mapDispatchToProps)(class extends Component {
' directory="/my/sub/dir",skylink="AACeCiD6WQG6DzDcCdIu3cFPSxMUMoQPx46NYSyijNMKUA",token="My Password"\n' +
' directory="/my/sub/dir",skylink="AACyjmDGoHqY7mTaxi-rkpnKUJGZK1B4UhrF74Nv6tY6Cg",token="My Password"\n' +
'\n' +
- 'To import JSON Skylinks, use the following syntax:\n' +
+ 'To import Skylinks using JSON syntax:\n' +
' [\n' +
' {\n' +
' "directory": "/",\n' +
@@ -56,56 +73,87 @@ export default connect(null, mapDispatchToProps)(class extends Component {
this.props.notifyInfo(msg)
}
+ onImportSkylinksReply = (_, arg) => {
+ this.props.notifyApplicationBusy(false);
+ if (arg.data.Success) {
+ console.log(arg.data.Result);
+ this.setState({
+ import_text: '',
+ imports_array: [],
+ second_stage: false,
+ });
+ } else {
+ this.props.notifyError(arg.data.Error);
+ }
+ };
+
processNext = () => {
- const items = this.state.import_list.split('\n');
- let importsArray = [];
- try {
- for (let item of items) {
- item = item.trim();
- if (item.startsWith('[')) {
- importsArray = JSON.parse(this.state.import_list.trim());
- break;
- } else if (item.indexOf('=') >= 0) {
- const parts = item.split(',')
- let importItem = {
- directory: '/',
- skylink: '',
- token: '',
- };
- for (let part of parts) {
- part = part.trim();
- const pair = part.split('=');
- if (pair.length !== 2) {
+ if (this.state.second_stage) {
+ try {
+ this.props.notifyApplicationBusy(true);
+ this.sendRequest(Constants.IPC_Import_Skylinks, {
+ Version: this.props.version,
+ JsonArray: this.state.imports_array,
+ });
+ } catch (e) {
+ this.props.notifyApplicationBusy(false);
+ this.props.notifyError(e);
+ }
+ } else {
+ const items = this.state.import_text.split('\n');
+ let importsArray = [];
+ try {
+ for (let item of items) {
+ item = item.trim();
+ if (item.startsWith('[')) {
+ importsArray = JSON.parse(this.state.import_text.trim());
+ break;
+ } else if (item.indexOf('=') >= 0) {
+ const parts = item.split(',')
+ let importItem = {
+ directory: '/',
+ skylink: '',
+ token: '',
+ };
+ for (let part of parts) {
+ part = part.trim();
+ const pair = part.split('=');
+ if (pair.length !== 2) {
+ throw new Error('Invalid syntax for import: directory="",skylink="",token=""');
+ }
+ importItem = {
+ ...importItem,
+ [pair[0].trim()]: pair[1].trim().replace(/"/g, ''),
+ };
+ }
+ if (!importItem.skylink) {
throw new Error('Invalid syntax for import: directory="",skylink="",token=""');
}
- importItem = {
- ...importItem,
- [pair[0].trim()]: pair[1].trim().replace(/"/g, ''),
- };
+ importsArray.push(importItem);
+ } else if (item.length > 0) {
+ importsArray.push({
+ directory: '/',
+ skylink: item,
+ });
}
- if (!importItem.skylink) {
- throw new Error('Invalid syntax for import: directory="",skylink="",token=""');
- }
- importsArray.push(importItem);
- } else if (item.length > 0) {
- importsArray.push({
- directory: '/',
- skylink: item,
- });
}
- }
- if (importsArray.length === 0) {
- throw new Error('Nothing to import');
+ if (importsArray.length === 0) {
+ throw new Error('Nothing to import');
+ }
+ this.setState({
+ imports_array: importsArray,
+ second_stage: true,
+ });
+ } catch (e) {
+ this.props.notifyError(e);
}
- this.props.importSkylinks(this.props.version, importsArray);
- } catch (e) {
- this.props.notifyError(e);
}
}
render() {
- return (
+ //
+ return this.props.AppBusy ? () : (
X