feat(react/bulk_actions): port add_label

This commit is contained in:
Elian Doran
2025-08-08 23:23:07 +03:00
parent 3dd6b05d2e
commit 6e1951b356
7 changed files with 122 additions and 99 deletions

View File

@@ -1,6 +1,7 @@
import { useContext, useEffect, useState } from "preact/hooks";
import { useContext, useEffect, useMemo, useState } from "preact/hooks";
import { EventData, EventNames } from "../../components/app_context";
import { ParentComponent } from "./ReactBasicWidget";
import SpacedUpdate from "../../services/spaced_update";
export default function useTriliumEvent<T extends EventNames>(eventName: T, handler: (data: EventData<T>) => void) {
const parentWidget = useContext(ParentComponent);
@@ -29,4 +30,12 @@ export default function useTriliumEvent<T extends EventNames>(eventName: T, hand
parentWidget[handlerName] = originalHandler;
};
}, [parentWidget]);
}
export function useSpacedUpdate(callback: () => Promise<void>, interval = 1000) {
const spacedUpdate = useMemo(() => {
return new SpacedUpdate(callback, interval);
}, [callback, interval]);
return spacedUpdate;
}