chore(react/collections/calendar): bring back saving of view

This commit is contained in:
Elian Doran
2025-09-05 17:18:02 +03:00
parent d6ccd106e6
commit 10d1ec1bb2
4 changed files with 28 additions and 38 deletions

View File

@@ -54,21 +54,16 @@ export function useTriliumEvents<T extends EventNames>(eventNames: T[], handler:
export function useSpacedUpdate(callback: () => void | Promise<void>, interval = 1000) {
const callbackRef = useRef(callback);
const spacedUpdateRef = useRef<SpacedUpdate>();
const spacedUpdateRef = useRef<SpacedUpdate>(new SpacedUpdate(
() => callbackRef.current(),
interval
));
// Update callback ref when it changes
useEffect(() => {
callbackRef.current = callback;
}, [callback]);
// Create SpacedUpdate instance only once
if (!spacedUpdateRef.current) {
spacedUpdateRef.current = new SpacedUpdate(
() => callbackRef.current(),
interval
);
}
// Update interval if it changes
useEffect(() => {
spacedUpdateRef.current?.setUpdateInterval(interval);