From a0445a307a34148eef6e6f3e5d601f1f9328a929 Mon Sep 17 00:00:00 2001 From: icarus Date: Wed, 22 Oct 2025 04:24:38 +0800 Subject: [PATCH] feat(hooks): add usePendingMap hook for managing pending state Implement a custom hook to track pending states with cache persistence. The hook provides methods to set and check pending status for given IDs, with automatic cleanup of undefined values. --- src/renderer/src/hooks/usePendingMap.ts | 31 +++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 src/renderer/src/hooks/usePendingMap.ts diff --git a/src/renderer/src/hooks/usePendingMap.ts b/src/renderer/src/hooks/usePendingMap.ts new file mode 100644 index 0000000000..3cc293941a --- /dev/null +++ b/src/renderer/src/hooks/usePendingMap.ts @@ -0,0 +1,31 @@ +import { useCache } from '@data/hooks/useCache' +import { useCallback } from 'react' + +export const usePendingMap = () => { + const [pendingMap, setPendingMap] = useCache('app.pending_map') + + const setPending = useCallback( + (id: string, value: boolean | undefined) => { + if (value !== undefined) { + setPendingMap({ + ...pendingMap, + [id]: value + }) + } else { + const newMap = { ...pendingMap } + delete newMap[id] + setPendingMap(newMap) + } + }, + [pendingMap, setPendingMap] + ) + + const isPending = useCallback( + (id: string) => { + return pendingMap[id] + }, + [pendingMap] + ) + + return { pendingMap, setPending, isPending } +}