From f817864033d7e57698cf5d4e1e632a2e14587772 Mon Sep 17 00:00:00 2001 From: Kirill Chernakov Date: Sun, 24 Nov 2024 11:59:18 +0400 Subject: [PATCH] wip: revalidate presets which are updated via `async-presets` --- keep-ui/utils/hooks/usePresets.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/keep-ui/utils/hooks/usePresets.ts b/keep-ui/utils/hooks/usePresets.ts index 6cc10873d..bfad2b3e0 100644 --- a/keep-ui/utils/hooks/usePresets.ts +++ b/keep-ui/utils/hooks/usePresets.ts @@ -9,6 +9,7 @@ import { useConfig } from "./useConfig"; import useSWRSubscription from "swr/subscription"; import { useWebsocket } from "./usePusher"; import { useSearchParams } from "next/navigation"; +import { useRevalidateMultiple } from "../state"; export const usePresets = (type?: string, useFilters?: boolean) => { const { data: session } = useSession(); @@ -31,6 +32,7 @@ export const usePresets = (type?: string, useFilters?: boolean) => { const presetsOrderRef = useRef(presetsOrderFromLS); const staticPresetsOrderRef = useRef(staticPresetsOrderFromLS); const { bind, unbind } = useWebsocket(); + const revalidateMultiple = useRevalidateMultiple(); useEffect(() => { presetsOrderRef.current = presetsOrderFromLS; @@ -88,6 +90,8 @@ export const usePresets = (type?: string, useFilters?: boolean) => { (_, { next }) => { const newPresets = (newPresets: Preset[]) => { updateLocalPresets(newPresets); + const presetKeys = newPresets.map((preset) => `preset/${preset.id}`); + revalidateMultiple(presetKeys); next(null, { presets: newPresets, isAsyncLoading: false,