refactor(client): deduplicate checks for title/icon editability

This commit is contained in:
Elian Doran
2026-04-10 22:36:13 +03:00
parent 14f761de36
commit c435050018
3 changed files with 13 additions and 8 deletions

View File

@@ -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;
}

View File

@@ -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} />;

View File

@@ -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 ]);