chore(react/ribbon): react to note type changes

This commit is contained in:
Elian Doran 2025-08-27 14:56:18 +03:00
parent 1c7dfa6c91
commit d92bd16042
No known key found for this signature in database
2 changed files with 5 additions and 8 deletions

View file

@ -62,12 +62,6 @@ export default class RibbonContainer extends NoteContextAwareWidget {
this.refreshWithNote(this.note, true); 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. * Executed as soon as the user presses the "Edit" floating button in a read-only text note.
* *

View file

@ -1,6 +1,6 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks"; import { useCallback, useEffect, useMemo, useRef, useState } from "preact/hooks";
import { t } from "../../services/i18n"; 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 "./style.css";
import { VNode } from "preact"; import { VNode } from "preact";
import BasicPropertiesTab from "./BasicPropertiesTab"; import BasicPropertiesTab from "./BasicPropertiesTab";
@ -161,9 +161,12 @@ const TAB_CONFIGURATION = numberObjectsInPlace<TabConfiguration>([
export default function Ribbon() { export default function Ribbon() {
const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId } = useNoteContext(); const { note, ntxId, hoistedNoteId, notePath, noteContext, componentId } = useNoteContext();
const noteType = useNoteProperty(note, "type");
const titleContext: TitleContext = { note }; const titleContext: TitleContext = { note };
const [ activeTabIndex, setActiveTabIndex ] = useState<number | undefined>(); const [ activeTabIndex, setActiveTabIndex ] = useState<number | undefined>();
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. // Automatically activate the first ribbon tab that needs to be activated whenever a note changes.
useEffect(() => { useEffect(() => {