diff --git a/.eslintignore b/.eslintignore index 43d539846..708d9a9d6 100644 --- a/.eslintignore +++ b/.eslintignore @@ -278,6 +278,9 @@ packages/app-desktop/gui/MainScreen/commands/showNoteContentProperties.js.map packages/app-desktop/gui/MainScreen/commands/showNoteProperties.d.ts packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js.map +packages/app-desktop/gui/MainScreen/commands/showPrompt.d.ts +packages/app-desktop/gui/MainScreen/commands/showPrompt.js +packages/app-desktop/gui/MainScreen/commands/showPrompt.js.map packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.d.ts packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js.map diff --git a/.gitignore b/.gitignore index 0ae109629..c53761af9 100644 --- a/.gitignore +++ b/.gitignore @@ -264,6 +264,9 @@ packages/app-desktop/gui/MainScreen/commands/showNoteContentProperties.js.map packages/app-desktop/gui/MainScreen/commands/showNoteProperties.d.ts packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js packages/app-desktop/gui/MainScreen/commands/showNoteProperties.js.map +packages/app-desktop/gui/MainScreen/commands/showPrompt.d.ts +packages/app-desktop/gui/MainScreen/commands/showPrompt.js +packages/app-desktop/gui/MainScreen/commands/showPrompt.js.map packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.d.ts packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js packages/app-desktop/gui/MainScreen/commands/showShareFolderDialog.js.map diff --git a/packages/app-desktop/app.ts b/packages/app-desktop/app.ts index ae6aee24b..e9bb47591 100644 --- a/packages/app-desktop/app.ts +++ b/packages/app-desktop/app.ts @@ -74,6 +74,7 @@ const commands = [ require('./gui/MainScreen/commands/toggleNoteList'), require('./gui/MainScreen/commands/toggleSideBar'), require('./gui/MainScreen/commands/toggleVisiblePanes'), + require('./gui/MainScreen/commands/showPrompt'), require('./gui/NoteEditor/commands/focusElementNoteBody'), require('./gui/NoteEditor/commands/focusElementNoteTitle'), require('./gui/NoteEditor/commands/showLocalSearch'), diff --git a/packages/app-desktop/gui/MainScreen/MainScreen.tsx b/packages/app-desktop/gui/MainScreen/MainScreen.tsx index c4c9154d8..5658408fc 100644 --- a/packages/app-desktop/gui/MainScreen/MainScreen.tsx +++ b/packages/app-desktop/gui/MainScreen/MainScreen.tsx @@ -135,6 +135,7 @@ const commands = [ require('./commands/openNote'), require('./commands/openFolder'), require('./commands/openTag'), + require('./commands/showPrompt'), ]; class MainScreenComponent extends React.Component { diff --git a/packages/app-desktop/gui/MainScreen/commands/showPrompt.ts b/packages/app-desktop/gui/MainScreen/commands/showPrompt.ts new file mode 100644 index 000000000..a9acaca5e --- /dev/null +++ b/packages/app-desktop/gui/MainScreen/commands/showPrompt.ts @@ -0,0 +1,41 @@ +import { CommandRuntime, CommandDeclaration, CommandContext } from '@joplin/lib/services/CommandService'; + +export const declaration: CommandDeclaration = { + name: 'showPrompt', +}; + +enum PromptInputType { + Dropdown = 'dropdown', + Datetime = 'datetime', + Tags = 'tags', + Text = 'text', +} + +interface PromptConfig { + label: string; + inputType?: PromptInputType; + value?: any; + autocomplete?: any[]; + buttons?: string[]; +} + +export const runtime = (comp: any): CommandRuntime => { + return { + execute: async (_context: CommandContext, config: PromptConfig) => { + return new Promise((resolve) => { + comp.setState({ + promptOptions: { + ...config, + onClose: async (answer: any, buttonType: string) => { + comp.setState({ promptOptions: null }); + resolve({ + answer: answer, + buttonType: buttonType, + }); + }, + }, + }); + }); + }, + }; +};