Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
refactor(client): deduplicate checks for title/icon editability
Elian Doranc43505001876
diff --git a/apps/client/src/entities/fnote.ts b/apps/client/src/entities/fnote.tsindex 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.tsxindex 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 <MobileNoteIconSwitcher note={note} icon={icon} disabled={isDisabled} />;diff --git a/apps/client/src/widgets/note_title.tsx b/apps/client/src/widgets/note_title.tsxindex 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 ]);