chore(react): prototype for note context

This commit is contained in:
Elian Doran
2025-08-25 11:48:56 +03:00
parent 89d2fcb81e
commit 660db3b3ab
6 changed files with 61 additions and 19 deletions

View File

@@ -17,9 +17,13 @@ import { CSSProperties } from "preact/compat";
export function useTriliumEvent<T extends EventNames>(eventName: T, handler: (data: EventData<T>) => void) {
const parentComponent = useContext(ParentComponent)!;
parentComponent.registerHandler(eventName, handler);
useEffect(() => {
parentComponent.registerHandler(eventName, handler);
return (() => parentComponent.removeHandler(eventName, handler));
}, [eventName, handler]);
useDebugValue(eventName);
return (() => parentComponent.removeHandler(eventName, handler));
}
export function useTriliumEvents<T extends EventNames>(eventNames: T[], handler: (data: EventData<T>, eventName: T) => void) {
@@ -199,7 +203,6 @@ export function useNoteContext() {
}, [ notePath ]);
useTriliumEvent("activeContextChanged", ({ noteContext }) => {
setNoteContext(noteContext);
setNotePath(noteContext.notePath);
});
useTriliumEvent("setNoteContext", ({ noteContext }) => {