diff --git a/vinvoor/src/hooks/useSeasons.ts b/vinvoor/src/hooks/useSeasons.ts index dca85db..f5221a7 100644 --- a/vinvoor/src/hooks/useSeasons.ts +++ b/vinvoor/src/hooks/useSeasons.ts @@ -14,7 +14,7 @@ export const useSeasons = () => { }; export const useSetSeason = () => { - const { mutate, ...rest } = usePatchSettings(); + const { mutate, ...other } = usePatchSettings(); const setSeason = ( id: number, @@ -26,5 +26,5 @@ export const useSetSeason = () => { >, ) => mutate({ season: id }, options); - return { setSeason, ...rest }; + return { setSeason, ...other }; }; diff --git a/vinvoor/src/hooks/useSettings.ts b/vinvoor/src/hooks/useSettings.ts index dcf1e10..3432b31 100644 --- a/vinvoor/src/hooks/useSettings.ts +++ b/vinvoor/src/hooks/useSettings.ts @@ -1,4 +1,4 @@ -import { useMutation, useQuery } from "@tanstack/react-query"; +import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { getApi, patchApi } from "../util/fetch"; import { converSettingsJSON, Settings, SettingsJSON } from "../types/settings"; @@ -11,8 +11,15 @@ export const useSettings = () => retry: 1, }); -export const usePatchSettings = () => - useMutation({ +export const usePatchSettings = () => { + const queryClient = useQueryClient(); + + return useMutation({ mutationFn: (args: Record) => patchApi(ENDPOINT, args), + onSuccess: () => + queryClient.invalidateQueries({ + predicate: query => query.queryKey[0] !== "settings", + }), }); +}; diff --git a/vinvoor/src/settings/Settings.tsx b/vinvoor/src/settings/Settings.tsx index 3d30ad2..9c34630 100644 --- a/vinvoor/src/settings/Settings.tsx +++ b/vinvoor/src/settings/Settings.tsx @@ -89,7 +89,10 @@ export const Settings = () => { - +