2020-10-18 22:52:10 +02:00
|
|
|
import { CommandContext, CommandDeclaration, CommandRuntime } from 'lib/services/CommandService';
|
2020-10-09 19:35:46 +02:00
|
|
|
import { _ } from 'lib/locale';
|
2020-07-03 23:32:39 +02:00
|
|
|
const Folder = require('lib/models/Folder');
|
2020-10-09 19:35:46 +02:00
|
|
|
const bridge = require('electron').remote.require('./bridge').default;
|
2020-07-03 23:32:39 +02:00
|
|
|
|
|
|
|
export const declaration:CommandDeclaration = {
|
2020-09-15 15:01:07 +02:00
|
|
|
name: 'newFolder',
|
2020-07-03 23:32:39 +02:00
|
|
|
label: () => _('New notebook'),
|
|
|
|
iconName: 'fa-book',
|
|
|
|
};
|
|
|
|
|
|
|
|
export const runtime = (comp:any):CommandRuntime => {
|
|
|
|
return {
|
2020-10-18 22:52:10 +02:00
|
|
|
execute: async (_context:CommandContext, parentId:string = null) => {
|
2020-07-03 23:32:39 +02:00
|
|
|
comp.setState({
|
|
|
|
promptOptions: {
|
|
|
|
label: _('Notebook title:'),
|
|
|
|
onClose: async (answer:string) => {
|
|
|
|
if (answer) {
|
|
|
|
let folder = null;
|
|
|
|
try {
|
|
|
|
const toSave:any = { title: answer };
|
|
|
|
if (parentId) toSave.parent_id = parentId;
|
|
|
|
folder = await Folder.save(toSave, { userSideValidation: true });
|
|
|
|
} catch (error) {
|
|
|
|
bridge().showErrorMessageBox(error.message);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (folder) {
|
|
|
|
comp.props.dispatch({
|
|
|
|
type: 'FOLDER_SELECT',
|
|
|
|
id: folder.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
comp.setState({ promptOptions: null });
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
|
|
|
};
|