From 9f217b88e45256452c47a0c8b24656e6a973cc4b Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Sat, 23 Aug 2025 20:59:13 +0300 Subject: [PATCH] refactor(react/ribbon): set up keyboard shortcuts --- .../attribute_widgets/attribute_editor.ts | 20 ------------------- apps/client/src/widgets/react/hooks.tsx | 1 - .../src/widgets/ribbon/OwnedAttributesTab.tsx | 8 ++------ .../ribbon/components/AttributeEditor.tsx | 12 ++++++++++- 4 files changed, 13 insertions(+), 28 deletions(-) delete mode 100644 apps/client/src/widgets/attribute_widgets/attribute_editor.ts diff --git a/apps/client/src/widgets/attribute_widgets/attribute_editor.ts b/apps/client/src/widgets/attribute_widgets/attribute_editor.ts deleted file mode 100644 index 38eec14e5..000000000 --- a/apps/client/src/widgets/attribute_widgets/attribute_editor.ts +++ /dev/null @@ -1,20 +0,0 @@ -export default class AttributeEditorWidget extends NoteContextAwareWidget implements EventListener<"entitiesReloaded">, EventListener<"addNewLabel">, EventListener<"addNewRelation"> { - - // triggered from keyboard shortcut - async addNewLabelEvent({ ntxId }: EventData<"addNewLabel">) { - if (this.isNoteContext(ntxId)) { - await this.refresh(); - - this.handleAddNewAttributeCommand("addNewLabel"); - } - } - - // triggered from keyboard shortcut - async addNewRelationEvent({ ntxId }: EventData<"addNewRelation">) { - if (this.isNoteContext(ntxId)) { - await this.refresh(); - - this.handleAddNewAttributeCommand("addNewRelation"); - } - } -} diff --git a/apps/client/src/widgets/react/hooks.tsx b/apps/client/src/widgets/react/hooks.tsx index 7a47674b8..45a751b10 100644 --- a/apps/client/src/widgets/react/hooks.tsx +++ b/apps/client/src/widgets/react/hooks.tsx @@ -450,7 +450,6 @@ export function useLegacyWidget(widgetFactory: () => T, { // Inject the note context. useEffect(() => { - console.log("Injecting note context"); if (noteContext && widget instanceof NoteContextAwareWidget) { widget.activeContextChangedEvent({ noteContext }); } diff --git a/apps/client/src/widgets/ribbon/OwnedAttributesTab.tsx b/apps/client/src/widgets/ribbon/OwnedAttributesTab.tsx index daf9d1495..bc1c73b3e 100644 --- a/apps/client/src/widgets/ribbon/OwnedAttributesTab.tsx +++ b/apps/client/src/widgets/ribbon/OwnedAttributesTab.tsx @@ -1,15 +1,11 @@ import AttributeEditor from "./components/AttributeEditor"; import { TabContext } from "./ribbon-interface"; -export default function OwnedAttributesTab({ note, notePath, componentId }: TabContext) { +export default function OwnedAttributesTab({ note, ...restProps }: TabContext) { return (
{ note && ( - + )}
) diff --git a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx index bb0e9b27e..14d96f6be 100644 --- a/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx +++ b/apps/client/src/widgets/ribbon/components/AttributeEditor.tsx @@ -76,7 +76,7 @@ const mentionSetup: MentionFeed[] = [ ]; -export default function AttributeEditor({ note, componentId, notePath }: { note: FNote, componentId: string, notePath?: string | null }) { +export default function AttributeEditor({ note, componentId, notePath, ntxId }: { note: FNote, componentId: string, notePath?: string | null, ntxId?: string | null }) { const [ state, setState ] = useState<"normal" | "showHelpTooltip" | "showAttributeDetail">(); const [ error, setError ] = useState(); const [ needsSaving, setNeedsSaving ] = useState(false); @@ -253,6 +253,16 @@ export default function AttributeEditor({ note, componentId, notePath }: { note: reloadAttributesCommand: refresh, updateAttributeListCommand: ({ attributes }: CommandListenerData<"updateAttributeList">) => renderOwnedAttributes(attributes as FAttribute[], false) }), [])); + + // Keyboard shortcuts + useTriliumEventBeta("addNewLabel", ({ ntxId: eventNtxId }) => { + if (eventNtxId !== ntxId) return; + handleAddNewAttributeCommand("addNewLabel"); + }); + useTriliumEventBeta("addNewRelation", ({ ntxId: eventNtxId }) => { + if (eventNtxId !== ntxId) return; + handleAddNewAttributeCommand("addNewRelation"); + }); return ( <>