From c2315a93419288bbd559c8f706c04d1efe9e1063 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 4 Jan 2025 21:52:41 +0200 Subject: [PATCH] refactor(client): use common method for checking if launch bar config --- src/public/app/entities/fnote.ts | 3 ++- src/public/app/services/branches.ts | 2 +- src/public/app/services/utils.ts | 10 +++++++++- src/public/app/widgets/note_title.js | 3 ++- src/public/app/widgets/note_tree.js | 3 ++- 5 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/public/app/entities/fnote.ts b/src/public/app/entities/fnote.ts index 6f4a58005..0fd19fff5 100644 --- a/src/public/app/entities/fnote.ts +++ b/src/public/app/entities/fnote.ts @@ -7,6 +7,7 @@ import cssClassManager from "../services/css_class_manager.js"; import { Froca } from '../services/froca-interface.js'; import FAttachment from './fattachment.js'; import FAttribute, { AttributeType } from './fattribute.js'; +import utils from '../services/utils.js'; const LABEL = 'label'; const RELATION = 'relation'; @@ -983,7 +984,7 @@ class FNote { } isLaunchBarConfig() { - return this.type === 'launcher' || ['_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers', "_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers" ].includes(this.noteId); + return this.type === 'launcher' || utils.isLaunchBarConfig(this.noteId); } isOptions() { diff --git a/src/public/app/services/branches.ts b/src/public/app/services/branches.ts index 9c2e66b1a..27884e77e 100644 --- a/src/public/app/services/branches.ts +++ b/src/public/app/services/branches.ts @@ -24,7 +24,7 @@ async function moveBeforeBranch(branchIdsToMove: string[], beforeBranchId: strin return; } - if (['root', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers', "_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers" ].includes(beforeBranch.noteId)) { + if (beforeBranch.noteId === "root" || utils.isLaunchBarConfig(beforeBranch.noteId)) { toastService.showError(t("branches.cannot-move-notes-here")); return; } diff --git a/src/public/app/services/utils.ts b/src/public/app/services/utils.ts index ba056e102..cad99c956 100644 --- a/src/public/app/services/utils.ts +++ b/src/public/app/services/utils.ts @@ -590,6 +590,13 @@ function isUpdateAvailable(latestVersion: string, currentVersion: string): boole return compareVersions(latestVersion, currentVersion) > 0; } +function isLaunchBarConfig(noteId: string) { + return [ + "_lbRoot", "_lbAvailableLaunchers", "_lbVisibleLaunchers", + "_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers" + ].includes(noteId); +} + export default { reloadFrontendApp, parseDate, @@ -632,5 +639,6 @@ export default { createImageSrcUrl, downloadSvg, compareVersions, - isUpdateAvailable + isUpdateAvailable, + isLaunchBarConfig }; diff --git a/src/public/app/widgets/note_title.js b/src/public/app/widgets/note_title.js index ff943ac1a..d18692228 100644 --- a/src/public/app/widgets/note_title.js +++ b/src/public/app/widgets/note_title.js @@ -6,6 +6,7 @@ import SpacedUpdate from "../services/spaced_update.js"; import appContext from "../components/app_context.js"; import branchService from "../services/branches.js"; import shortcutService from "../services/shortcuts.js"; +import utils from "../services/utils.js"; const TPL = `
@@ -73,7 +74,7 @@ export default class NoteTitleWidget extends NoteContextAwareWidget { async refreshWithNote(note) { const isReadOnly = (note.isProtected && !protectedSessionHolder.isProtectedSessionAvailable()) - || ['_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers', "_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers" ].includes(note.noteId) + || utils.isLaunchBarConfig(note.noteId) || this.noteContext.viewScope.viewMode !== 'default'; this.$noteTitle.val( diff --git a/src/public/app/widgets/note_tree.js b/src/public/app/widgets/note_tree.js index f5a1e821b..b0acc39ec 100644 --- a/src/public/app/widgets/note_tree.js +++ b/src/public/app/widgets/note_tree.js @@ -392,7 +392,8 @@ export default class NoteTreeWidget extends NoteContextAwareWidget { autoExpandMS: 600, preventLazyParents: false, dragStart: (node, data) => { - if (['root', '_hidden', '_lbRoot', '_lbAvailableLaunchers', '_lbVisibleLaunchers', "_lbMobileRoot", "_lbMobileAvailableLaunchers", "_lbMobileVisibleLaunchers" ].includes(node.data.noteId) + if (node.data.noteId === "root" + || utils.isLaunchBarConfig(node.data.noteId) || node.data.noteId.startsWith("_options")) { return false; }