From c43505001876bf7aec88be91c4c0719b6af2234f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 10 Apr 2026 22:36:13 +0300 Subject: [PATCH] refactor(client): deduplicate checks for title/icon editability --- apps/client/src/entities/fnote.ts | 10 ++++++++++ apps/client/src/widgets/note_icon.tsx | 6 ++---- apps/client/src/widgets/note_title.tsx | 5 +---- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.ts index 5fe7caf33c..a30a83975a 100644 --- a/apps/client/src/entities/fnote.ts +++ b/apps/client/src/entities/fnote.ts @@ -236,6 +236,16 @@ export default class FNote { return this.hasAttribute("label", "archived"); } + /** + * Returns true if the note's metadata (title, icon) should not be editable. + * This applies to system notes like options, help, and launch bar configuration. + */ + get isMetadataReadOnly() { + return utils.isLaunchBarConfig(this.noteId) + || this.noteId.startsWith("_help_") + || this.noteId.startsWith("_options"); + } + getChildNoteIds() { return this.children; } diff --git a/apps/client/src/widgets/note_icon.tsx b/apps/client/src/widgets/note_icon.tsx index b3d15d6889..c6ed7e618b 100644 --- a/apps/client/src/widgets/note_icon.tsx +++ b/apps/client/src/widgets/note_icon.tsx @@ -13,7 +13,7 @@ import { CellComponentProps, Grid } from "react-window"; import FNote from "../entities/fnote"; import attributes from "../services/attributes"; import server from "../services/server"; -import { isDesktop, isLaunchBarConfig, isMobile } from "../services/utils"; +import { isDesktop, isMobile } from "../services/utils"; import ActionButton from "./react/ActionButton"; import Dropdown from "./react/Dropdown"; import { FormDropdownDivider, FormListItem } from "./react/FormList"; @@ -43,9 +43,7 @@ export default function NoteIcon() { }, [ note, iconClass, workspaceIconClass ]); const isDisabled = viewScope?.viewMode !== "default" - || (note?.noteId && isLaunchBarConfig(note.noteId)) - || note?.noteId?.startsWith("_help_") - || note?.noteId?.startsWith("_options"); + || note?.isMetadataReadOnly; if (isMobile()) { return ; diff --git a/apps/client/src/widgets/note_title.tsx b/apps/client/src/widgets/note_title.tsx index 03e02beee2..dac6a498e0 100644 --- a/apps/client/src/widgets/note_title.tsx +++ b/apps/client/src/widgets/note_title.tsx @@ -9,7 +9,6 @@ import { t } from "../services/i18n"; import protected_session_holder from "../services/protected_session_holder"; import server from "../services/server"; import { isIMEComposing } from "../services/shortcuts"; -import { isLaunchBarConfig } from "../services/utils"; import FormTextBox from "./react/FormTextBox"; import { useNoteContext, useNoteProperty, useSpacedUpdate, useTriliumEvent, useTriliumEvents } from "./react/hooks"; @@ -27,9 +26,7 @@ export default function NoteTitleWidget(props: {className?: string}) { const isReadOnly = note === null || note === undefined || (note.isProtected && !protected_session_holder.isProtectedSessionAvailable()) - || isLaunchBarConfig(note.noteId) - || note.noteId.startsWith("_help_") - || note.noteId.startsWith("_options") + || note.isMetadataReadOnly || viewScope?.viewMode !== "default"; setReadOnly(isReadOnly); }, [ note, note?.noteId, note?.isProtected, viewScope?.viewMode ]);