From c0beab8a5db7574d3795adbaf565d34221308f4f Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 21 Aug 2025 20:38:19 +0300 Subject: [PATCH] chore(react/ribbon): display current note type --- apps/client/src/widgets/note_type.ts | 15 +-- apps/client/src/widgets/react/Dropdown.tsx | 10 +- .../src/widgets/ribbon/BasicPropertiesTab.tsx | 98 ++++++++++++------- .../ribbon_widgets/basic_properties.ts | 2 +- 4 files changed, 70 insertions(+), 55 deletions(-) diff --git a/apps/client/src/widgets/note_type.ts b/apps/client/src/widgets/note_type.ts index cb1d53bb3..fe45fa233 100644 --- a/apps/client/src/widgets/note_type.ts +++ b/apps/client/src/widgets/note_type.ts @@ -14,8 +14,7 @@ const NOT_SELECTABLE_NOTE_TYPES = NOTE_TYPES.filter((nt) => nt.reserved || nt.st const TPL = /*html*/` `; @@ -36,7 +35,6 @@ export default class NoteTypeWidget extends NoteContextAwareWidget { this.$noteTypeDropdown = this.$widget.find(".note-type-dropdown"); this.$noteTypeButton = this.$widget.find(".note-type-button"); - this.$noteTypeDesc = this.$widget.find(".note-type-desc"); this.$widget.on("click", ".dropdown-item", () => this.dropdown.toggle()); } @@ -105,18 +103,7 @@ export default class NoteTypeWidget extends NoteContextAwareWidget { } } - async findTypeTitle(type: NoteType, mime: string) { - if (type === "code") { - const mimeTypes = mimeTypesService.getMimeTypes(); - const found = mimeTypes.find((mt) => mt.mime === mime); - return found ? found.title : mime; - } else { - const noteType = NOTE_TYPES.find((nt) => nt.type === type); - - return noteType ? noteType.title : type; - } - } async save(type: NoteType, mime?: string) { if (type === this.note?.type && mime === this.note?.mime) { diff --git a/apps/client/src/widgets/react/Dropdown.tsx b/apps/client/src/widgets/react/Dropdown.tsx index 49a1ac228..2578aec31 100644 --- a/apps/client/src/widgets/react/Dropdown.tsx +++ b/apps/client/src/widgets/react/Dropdown.tsx @@ -14,9 +14,10 @@ interface DropdownProps { dropdownContainerClassName?: string; hideToggleArrow?: boolean; disabled?: boolean; + text?: ComponentChildren; } -export default function Dropdown({ className, buttonClassName, isStatic, children, title, dropdownContainerStyle, dropdownContainerClassName, hideToggleArrow, disabled }: DropdownProps) { +export default function Dropdown({ className, buttonClassName, isStatic, children, title, text, dropdownContainerStyle, dropdownContainerClassName, hideToggleArrow, disabled }: DropdownProps) { const dropdownRef = useRef(null); const triggerRef = useRef(null); @@ -56,7 +57,7 @@ export default function Dropdown({ className, buttonClassName, isStatic, childre return (
NOTE_TYPES.filter((nt) => !nt.reserved && !nt.static), []); const [ codeNotesMimeTypes ] = useTriliumOption("codeNotesMimeTypes"); const mimeTypes = useMemo(() => mime_types.getMimeTypes().filter(mimeType => mimeType.enabled), [ codeNotesMimeTypes ]); + + const { note } = useNoteContext(); + const type = useNoteProperty(note, "type") ?? undefined; + const mime = useNoteProperty(note, "mime"); return ( - - {noteTypes.map(noteType => { - const badges: FormListBadge[] = []; - if (noteType.isNew) { - badges.push({ - className: "new-note-type-badge", - text: t("note_types.new-feature") - }); - } - if (noteType.isBeta) { - badges.push({ - text: t("note_types.beta-feature") - }); - } + <> + {t("basic_properties.note_type")}:   + {findTypeTitle(type, mime)}} + > + {noteTypes.map(noteType => { + const badges: FormListBadge[] = []; + if (noteType.isNew) { + badges.push({ + className: "new-note-type-badge", + text: t("note_types.new-feature") + }); + } + if (noteType.isBeta) { + badges.push({ + text: t("note_types.beta-feature") + }); + } - if (noteType.type !== "code") { - return ( - {noteType.title} - ); - } else { - return ( - <> - - - {noteType.title} - - - ) - } - })} + if (noteType.type !== "code") { + return ( + {noteType.title} + ); + } else { + return ( + <> + + + {noteType.title} + + + ) + } + })} - {mimeTypes.map(mimeType => ( - {mimeType.title} - ))} - + {mimeTypes.map(mimeType => ( + {mimeType.title} + ))} + + ) +} + +function findTypeTitle(type?: NoteType, mime?: string) { + if (type === "code") { + const mimeTypes = mime_types.getMimeTypes(); + const found = mimeTypes.find((mt) => mt.mime === mime); + + return found ? found.title : mime; + } else { + const noteType = NOTE_TYPES.find((nt) => nt.type === type); + + return noteType ? noteType.title : type; + } } \ No newline at end of file diff --git a/apps/client/src/widgets/ribbon_widgets/basic_properties.ts b/apps/client/src/widgets/ribbon_widgets/basic_properties.ts index 603dee60f..e5f2ca8a2 100644 --- a/apps/client/src/widgets/ribbon_widgets/basic_properties.ts +++ b/apps/client/src/widgets/ribbon_widgets/basic_properties.ts @@ -11,7 +11,7 @@ import NoteLanguageWidget from "../note_language.js"; const TPL = /*html*/`
- ${t("basic_properties.note_type")}:   +