Skip to content

Commit

Permalink
wip: revalidate presets which are updated via async-presets
Browse files Browse the repository at this point in the history
(cherry picked from commit f817864)
  • Loading branch information
Kiryous committed Nov 24, 2024
1 parent 6fabb32 commit 07ddcd0
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions keep-ui/utils/hooks/usePresets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 07ddcd0

Please sign in to comment.