From 72cc54a83ff2266e3ac3129ad0a8fc873496d76a Mon Sep 17 00:00:00 2001 From: zadam Date: Tue, 17 Mar 2020 21:39:26 +0100 Subject: [PATCH] fixed global create new day note --- src/public/javascripts/desktop.js | 2 +- src/public/javascripts/services/entrypoints.js | 17 ++++++++++------- .../javascripts/services/frontend_script_api.js | 2 +- .../javascripts/services/keyboard_actions.js | 12 ------------ src/public/javascripts/services/load_results.js | 2 +- src/public/javascripts/widgets/note_title.js | 2 +- 6 files changed, 14 insertions(+), 23 deletions(-) diff --git a/src/public/javascripts/desktop.js b/src/public/javascripts/desktop.js index 91a6c9016..55bfbadfd 100644 --- a/src/public/javascripts/desktop.js +++ b/src/public/javascripts/desktop.js @@ -71,7 +71,7 @@ import bundleService from "./services/bundle.js"; if (utils.isElectron()) { require('electron').ipcRenderer.on('globalShortcut', async function(event, actionName) { - keyboardActionService.triggerAction(actionName); + appContext.triggerCommand(actionName); }); } diff --git a/src/public/javascripts/services/entrypoints.js b/src/public/javascripts/services/entrypoints.js index 4bb696fb2..ba6605a6a 100644 --- a/src/public/javascripts/services/entrypoints.js +++ b/src/public/javascripts/services/entrypoints.js @@ -8,6 +8,7 @@ import appContext from "./app_context.js"; import Component from "../widgets/component.js"; import toastService from "./toast.js"; import noteCreateService from "./note_create.js"; +import ws from "./ws.js"; export default class Entrypoints extends Component { constructor() { @@ -65,18 +66,18 @@ export default class Entrypoints extends Component { async createNoteIntoDayNoteCommand() { const todayNote = await dateNoteService.getTodayNote(); - const {note} = await server.post(`notes/${todayNote.noteId}/children?target=into`, { - title: 'new note', - content: '', + const {note} = await noteCreateService.createNote(todayNote.noteId, { + isProtected: todayNote.isProtected, type: 'text', - isProtected: todayNote.isProtected + title: 'new note', + content: '' }); - await treeService.expandToNote(note.noteId); + await ws.waitForMaxKnownSyncId(); - const tabContext = await appContext.tabManager.openTabWithNote(note.noteId, true); + await appContext.tabManager.openTabWithNote(note.noteId, false); - appContext.triggerCommand('focusAndSelectTitle'); + appContext.triggerEvent('focusAndSelectTitle'); } async toggleNoteHoistingCommand() { @@ -137,6 +138,7 @@ export default class Entrypoints extends Component { backInNoteHistoryCommand() { if (utils.isElectron()) { + // standard JS version does not work completely correctly in electron const webContents = require('electron').remote.getCurrentWebContents(); const activeIndex = parseInt(webContents.getActiveIndex()); @@ -149,6 +151,7 @@ export default class Entrypoints extends Component { forwardInNoteHistoryCommand() { if (utils.isElectron()) { + // standard JS version does not work completely correctly in electron const webContents = require('electron').remote.getCurrentWebContents(); const activeIndex = parseInt(webContents.getActiveIndex()); diff --git a/src/public/javascripts/services/frontend_script_api.js b/src/public/javascripts/services/frontend_script_api.js index 8e1ca4d54..ed3a3272c 100644 --- a/src/public/javascripts/services/frontend_script_api.js +++ b/src/public/javascripts/services/frontend_script_api.js @@ -58,7 +58,7 @@ function FrontendScriptApi(startNote, currentNote, originEntity = null, $contain await ws.waitForMaxKnownSyncId(); await appContext.tabManager.getActiveTabContext().setNote(notePath); - appContext.triggerCommand('focusAndSelectTitle'); + appContext.triggerEvent('focusAndSelectTitle'); }; /** diff --git a/src/public/javascripts/services/keyboard_actions.js b/src/public/javascripts/services/keyboard_actions.js index a202a284e..7ec249404 100644 --- a/src/public/javascripts/services/keyboard_actions.js +++ b/src/public/javascripts/services/keyboard_actions.js @@ -66,16 +66,6 @@ function setElementActionHandler($el, actionName, handler) { }); } -async function triggerAction(actionName) { - const action = await getAction(actionName); - - if (!action.handler) { - throw new Error(`Action ${actionName} has no handler`); - } - - await action.handler(); -} - async function getAction(actionName, silent = false) { await keyboardActionsLoaded; @@ -119,8 +109,6 @@ function updateDisplayedShortcuts($container) { export default { setElementActionHandler, - triggerAction, - getAction, updateDisplayedShortcuts, setupActionsForElement, getActionsForScope diff --git a/src/public/javascripts/services/load_results.js b/src/public/javascripts/services/load_results.js index 678afdc33..c51707686 100644 --- a/src/public/javascripts/services/load_results.js +++ b/src/public/javascripts/services/load_results.js @@ -18,7 +18,7 @@ export default class LoadResults { this.options = []; } - addNote(noteId, sourceId) {console.log("Adding", noteId, sourceId); + addNote(noteId, sourceId) { this.noteIdToSourceId[noteId] = this.noteIdToSourceId[noteId] || []; if (!this.noteIdToSourceId[noteId].includes(sourceId)) { diff --git a/src/public/javascripts/widgets/note_title.js b/src/public/javascripts/widgets/note_title.js index 5c6eb2404..305a3b672 100644 --- a/src/public/javascripts/widgets/note_title.js +++ b/src/public/javascripts/widgets/note_title.js @@ -70,7 +70,7 @@ export default class NoteTitleWidget extends TabAwareWidget { } } - focusAndSelectTitleCommand() { + focusAndSelectTitleEvent() { if (this.tabContext && this.tabContext.isActive()) { this.$noteTitle .trigger('focus')