diff --git a/package-lock.json b/package-lock.json index 6eda4a9af..1a4797ff7 100644 --- a/package-lock.json +++ b/package-lock.json @@ -3383,15 +3383,15 @@ } }, "electron-rebuild": { - "version": "1.8.8", - "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.8.8.tgz", - "integrity": "sha512-9a/VGbVpTJcuBaZa8yMcegqJ5flGPYDo363AxXDMxY4ZHPtFMLedGzQW9+720SIS1cvjX8B0zC+vMHO75ncOiA==", + "version": "1.9.0", + "resolved": "https://registry.npmjs.org/electron-rebuild/-/electron-rebuild-1.9.0.tgz", + "integrity": "sha512-lnHW+gJIhukqVhME2v+LRDldafWwP0kGOPEpPuj59+F4NHEfu/vOjk8OLBcgDGt72CSWZm7zFUDE07oZxQJbHw==", "dev": true, "requires": { "colors": "^1.3.3", "debug": "^4.1.1", "detect-libc": "^1.0.3", - "fs-extra": "^7.0.1", + "fs-extra": "^8.1.0", "node-abi": "^2.11.0", "node-gyp": "^6.0.1", "ora": "^3.4.0", @@ -3399,21 +3399,10 @@ "yargs": "^13.2.4" }, "dependencies": { - "fs-extra": { - "version": "7.0.1", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-7.0.1.tgz", - "integrity": "sha512-YJDaCJZEnBmcbw13fvdAM9AwNOJwOzrE4pqMqBq5nFiEqXUqHwlK4B+3pUw6JNvfSPtX05xFHtYy/1ni01eGCw==", - "dev": true, - "requires": { - "graceful-fs": "^4.1.2", - "jsonfile": "^4.0.0", - "universalify": "^0.1.0" - } - }, "rxjs": { - "version": "6.5.3", - "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.3.tgz", - "integrity": "sha512-wuYsAYYFdWTAnAaPoKGNhfpWwKZbJW+HgAJ+mImp+Epl7BG8oNWBCTyRM8gba9k4lk8BgWdoYm21Mo/RYhhbgA==", + "version": "6.5.4", + "resolved": "https://registry.npmjs.org/rxjs/-/rxjs-6.5.4.tgz", + "integrity": "sha512-naMQXcgEo3csAEGvw/NydRA0fuS2nDZJiw1YUWFKU7aPPAPGZEsD4Iimit96qwCieH6y614MCLYwdkrWx7z/7Q==", "dev": true, "requires": { "tslib": "^1.9.0" @@ -7062,9 +7051,9 @@ } }, "node-gyp": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-6.0.1.tgz", - "integrity": "sha512-udHG4hGe3Ji97AYJbJhaRwuSOuQO7KHnE4ZPH3Sox3tjRZ+bkBsDvfZ7eYA1qwD8eLWr//193x806ss3HFTPRw==", + "version": "6.1.0", + "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-6.1.0.tgz", + "integrity": "sha512-h4A2zDlOujeeaaTx06r4Vy+8MZ1679lU+wbCKDS4ZtvY2A37DESo37oejIw0mtmR3+rvNwts5B6Kpt1KrNYdNw==", "dev": true, "requires": { "env-paths": "^2.2.0", diff --git a/package.json b/package.json index 292149089..d3de6cd0a 100644 --- a/package.json +++ b/package.json @@ -80,7 +80,7 @@ "electron": "6.0.12", "electron-builder": "22.2.0", "electron-packager": "14.2.0", - "electron-rebuild": "1.8.8", + "electron-rebuild": "1.9.0", "jsdoc": "3.6.3", "lorem-ipsum": "2.0.3" }, diff --git a/src/public/javascripts/dialogs/attributes.js b/src/public/javascripts/dialogs/attributes.js index fffa9254a..d97a0e048 100644 --- a/src/public/javascripts/dialogs/attributes.js +++ b/src/public/javascripts/dialogs/attributes.js @@ -172,12 +172,11 @@ function AttributesModel() { toastService.showMessage("Attributes have been saved."); - const ctx = appContext.getActiveTabContext(); - - ctx.attributes.refreshAttributes(); + appContext.getActiveTabContext().attributes.refreshAttributes(); + // reload noteDetailService.reload(); - treeService.reload(); + appContext.trigger('reloadTree'); }; function addLastEmptyRow() { diff --git a/src/public/javascripts/services/branches.js b/src/public/javascripts/services/branches.js index 89682ed14..cef7655b1 100644 --- a/src/public/javascripts/services/branches.js +++ b/src/public/javascripts/services/branches.js @@ -7,6 +7,7 @@ import treeUtils from "./tree_utils.js"; import hoistedNoteService from "./hoisted_note.js"; import noteDetailService from "./note_detail.js"; import ws from "./ws.js"; +import appContext from "./app_context.js"; async function moveBeforeNode(branchIdsToMove, beforeBranchId) { branchIdsToMove = await filterRootNote(branchIdsToMove); @@ -147,7 +148,7 @@ async function deleteNodes(branchIdsToDelete) { const noteIds = Array.from(new Set(nodes.map(node => node.getParent().data.noteId))); - await treeService.reloadNotes(noteIds); + appContext.trigger('reloadNotes', {noteIds}); return true; } diff --git a/src/public/javascripts/services/cloning.js b/src/public/javascripts/services/cloning.js index 5088d1cad..aa2384b86 100644 --- a/src/public/javascripts/services/cloning.js +++ b/src/public/javascripts/services/cloning.js @@ -1,6 +1,6 @@ -import treeService from './tree.js'; import treeCache from './tree_cache.js'; import server from './server.js'; +import appContext from "./app_context.js"; async function cloneNoteTo(childNoteId, parentNoteId, prefix) { const resp = await server.put('notes/' + childNoteId + '/clone-to/' + parentNoteId, { @@ -12,7 +12,7 @@ async function cloneNoteTo(childNoteId, parentNoteId, prefix) { return; } - await treeService.reloadNotes([childNoteId, parentNoteId]); + appContext.trigger('reloadNotes', {noteIds: [childNoteId, parentNoteId]}); } // beware that first arg is noteId and second is branchId! @@ -26,7 +26,7 @@ async function cloneNoteAfter(noteId, afterBranchId) { const afterBranch = treeCache.getBranch(afterBranchId); - await treeService.reloadNotes([noteId, afterBranch.parentNoteId]); + appContext.trigger('reloadNotes', {noteIds: [noteId, afterBranch.parentNoteId]}); } export default { diff --git a/src/public/javascripts/services/hoisted_note.js b/src/public/javascripts/services/hoisted_note.js index fc2617de6..140d3677d 100644 --- a/src/public/javascripts/services/hoisted_note.js +++ b/src/public/javascripts/services/hoisted_note.js @@ -2,6 +2,7 @@ import optionsService from './options.js'; import server from "./server.js"; import tree from "./tree.js"; import noteDetailService from "./note_detail.js"; +import appContext from "./app_context.js"; let hoistedNoteId = 'root'; @@ -28,13 +29,7 @@ async function setHoistedNoteId(noteId) { await server.put('options/hoistedNoteId/' + noteId); - await tree.reload(); - - const activeTabContext = appContext.getActiveTabContext(); - - if (activeTabContext) { - await tree.activateNote(activeTabContext.notePath); - } + appContext.trigger('hoistedNoteChanged'); } async function unhoist() { diff --git a/src/public/javascripts/services/import.js b/src/public/javascripts/services/import.js index fb394a338..82ea93916 100644 --- a/src/public/javascripts/services/import.js +++ b/src/public/javascripts/services/import.js @@ -3,6 +3,7 @@ import treeService from "./tree.js"; import server from "./server.js"; import ws from "./ws.js"; import utils from "./utils.js"; +import appContext from "./app_context.js"; export async function uploadFiles(parentNoteId, files, options) { if (files.length === 0) { @@ -63,7 +64,7 @@ ws.subscribeToMessages(async message => { toastService.showPersistent(toast); - await treeService.reloadNotes([message.result.parentNoteId]); + appContext.trigger('reloadNotes', {noteIds: [message.result.parentNoteId]}); if (message.result.importedNoteId) { const node = await treeService.activateNote(message.result.importedNoteId); diff --git a/src/public/javascripts/services/protected_session.js b/src/public/javascripts/services/protected_session.js index 31d5db4e6..ed65da06f 100644 --- a/src/public/javascripts/services/protected_session.js +++ b/src/public/javascripts/services/protected_session.js @@ -48,10 +48,7 @@ async function setupProtectedSession(password) { protectedSessionHolder.setProtectedSessionId(response.protectedSessionId); protectedSessionHolder.touchProtectedSession(); - await treeService.reload(); - - // it's important that tree has been already reloaded at this point since detail also uses tree cache (for book) - await appContext.reloadAllTabs(); + appContext.trigger('protectedSessionStarted'); if (protectedSessionDeferred !== null) { import("../dialogs/protected_session.js").then(dialog => dialog.close()); diff --git a/src/public/javascripts/services/tree.js b/src/public/javascripts/services/tree.js index f8a14e880..6343005a2 100644 --- a/src/public/javascripts/services/tree.js +++ b/src/public/javascripts/services/tree.js @@ -10,7 +10,6 @@ import treeBuilder from "./tree_builder.js"; import hoistedNoteService from '../services/hoisted_note.js'; import optionsService from "../services/options.js"; import bundle from "./bundle.js"; -import keyboardActionService from "./keyboard_actions.js"; import appContext from "./app_context.js"; let setFrontendAsLoaded; @@ -201,14 +200,6 @@ async function getSomeNotePath(note) { return path.reverse().join('/'); } -async function setExpandedToServer(branchId, isExpanded) { - utils.assertArguments(branchId); - - const expandedNum = isExpanded ? 1 : 0; - - await server.put('branches/' + branchId + '/expanded/' + expandedNum); -} - async function treeInitialized() { if (appContext.getTabContexts().length > 0) { // this is just tree reload - tabs are already in place @@ -287,23 +278,6 @@ async function treeInitialized() { setFrontendAsLoaded(); } -async function reload() { - const notes = await loadTreeData(); - - const activeNode = appContext.getMainNoteTree().getActiveNode(); - - const activeNotePath = activeNode !== null ? await treeUtils.getNotePath(activeNode) : null; - - await appContext.getMainNoteTree().reload(notes); - - // reactivate originally activated node, but don't trigger note loading - if (activeNotePath) { - const node = await appContext.getMainNoteTree().getNodeFromPath(activeNotePath, true); - - await node.setActive(true, {noEvents: true}); - } -} - function isNotePathInAddress() { const [notePath, tabId] = getHashValueFromAddress(); @@ -503,24 +477,10 @@ ws.subscribeToOutsideSyncMessages(async syncData => { }); if (noteIdsToRefresh.size > 0) { - await reloadNotes(Array.from(noteIdsToRefresh)); + appContext.trigger('reloadNotes', {noteIds: Array.from(noteIdsToRefresh)}); } }); -async function reloadNotes(noteIds, activateNotePath = null) { - if (noteIds.length === 0) { - return; - } - - await treeCache.reloadNotes(noteIds); - - if (!activateNotePath) { - activateNotePath = appContext.getActiveTabNotePath(); - } - - appContext.trigger('notesReloaded', { noteIds, activateNotePath }); -} - $(window).bind('hashchange', async function() { if (isNotePathInAddress()) { const [notePath, tabId] = getHashValueFromAddress(); @@ -532,7 +492,7 @@ $(window).bind('hashchange', async function() { async function duplicateNote(noteId, parentNoteId) { const {note} = await server.post(`notes/${noteId}/duplicate/${parentNoteId}`); - await reload(); + await ws.waitForMaxKnownSyncId(); await activateNote(note.noteId); @@ -543,7 +503,6 @@ async function duplicateNote(noteId, parentNoteId) { frontendLoaded.then(bundle.executeStartupBundles); export default { - reload, setProtected, activateNote, setPrefix, @@ -551,8 +510,6 @@ export default { sortAlphabetically, loadTreeData, treeInitialized, - setExpandedToServer, - reloadNotes, resolveNotePath, getSomeNotePath, createNewTopLevelNote, diff --git a/src/public/javascripts/widgets/note_detail.js b/src/public/javascripts/widgets/note_detail.js index e40683091..38928bd61 100644 --- a/src/public/javascripts/widgets/note_detail.js +++ b/src/public/javascripts/widgets/note_detail.js @@ -201,4 +201,12 @@ export default class NoteDetailWidget extends TabAwareWidget { debug: true }); } + + hoistedNoteChangedListener() { + this.refresh(); + } + + protectedSessionStartedListener() { + this.refresh(); + } } \ No newline at end of file diff --git a/src/public/javascripts/widgets/note_tree.js b/src/public/javascripts/widgets/note_tree.js index c4bf6e8c1..46107f50f 100644 --- a/src/public/javascripts/widgets/note_tree.js +++ b/src/public/javascripts/widgets/note_tree.js @@ -13,6 +13,7 @@ import treeChangesService from "../services/branches.js"; import ws from "../services/ws.js"; import appContext from "../services/app_context.js"; import TabAwareWidget from "./tab_aware_widget.js"; +import server from "../services/server.js"; const TPL = `