From d92bd1604263de927080e22dd449a9adb78155fe Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Wed, 27 Aug 2025 14:56:18 +0300 Subject: [PATCH] chore(react/ribbon): react to note type changes --- apps/client/src/widgets/containers/ribbon_container.ts | 6 ------ apps/client/src/widgets/ribbon/Ribbon.tsx | 7 +++++-- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/apps/client/src/widgets/containers/ribbon_container.ts b/apps/client/src/widgets/containers/ribbon_container.ts index 31f26a10a..a2a8c0f84 100644 --- a/apps/client/src/widgets/containers/ribbon_container.ts +++ b/apps/client/src/widgets/containers/ribbon_container.ts @@ -62,12 +62,6 @@ export default class RibbonContainer extends NoteContextAwareWidget { this.refreshWithNote(this.note, true); } } - - async noteTypeMimeChangedEvent() { - // We are ignoring the event which triggers a refresh since it is usually already done by a different - // event and causing a race condition in which the items appear twice. - } - /** * Executed as soon as the user presses the "Edit" floating button in a read-only text note. * diff --git a/apps/client/src/widgets/ribbon/Ribbon.tsx b/apps/client/src/widgets/ribbon/Ribbon.tsx index 3a937e730..61f68fe51 100644 --- a/apps/client/src/widgets/ribbon/Ribbon.tsx +++ b/apps/client/src/widgets/ribbon/Ribbon.tsx @@ -1,6 +1,6 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks"; import { t } from "../../services/i18n"; -import { useNoteContext, useStaticTooltip, useTooltip, useTriliumEvent, useTriliumEvents } from "../react/hooks"; +import { useNoteContext, useNoteProperty, useStaticTooltip, useTooltip, useTriliumEvent, useTriliumEvents } from "../react/hooks"; import "./style.css"; import { VNode } from "preact"; import BasicPropertiesTab from "./BasicPropertiesTab"; @@ -161,9 +161,12 @@ const TAB_CONFIGURATION = numberObjectsInPlace([ export default function Ribbon() { const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId } = useNoteContext(); + const noteType = useNoteProperty(note, "type"); const titleContext: TitleContext = { note }; const [ activeTabIndex, setActiveTabIndex ] = useState(); - const filteredTabs = useMemo(() => TAB_CONFIGURATION.filter(tab => typeof tab.show === "boolean" ? tab.show : tab.show?.(titleContext)), [ titleContext, note ]); + const filteredTabs = useMemo( + () => TAB_CONFIGURATION.filter(tab => typeof tab.show === "boolean" ? tab.show : tab.show?.(titleContext)), + [ titleContext, note, noteType ]); // Automatically activate the first ribbon tab that needs to be activated whenever a note changes. useEffect(() => {