Skip to content

Commit

Permalink
vinvoor: invalidate queries when changing settings
Browse files Browse the repository at this point in the history
  • Loading branch information
Topvennie committed Oct 3, 2024
1 parent 24490c0 commit 63873bb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
4 changes: 2 additions & 2 deletions vinvoor/src/hooks/useSeasons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const useSeasons = () => {
};

export const useSetSeason = () => {
const { mutate, ...rest } = usePatchSettings();
const { mutate, ...other } = usePatchSettings();

const setSeason = (
id: number,
Expand All @@ -26,5 +26,5 @@ export const useSetSeason = () => {
>,
) => mutate({ season: id }, options);

return { setSeason, ...rest };
return { setSeason, ...other };
};
13 changes: 10 additions & 3 deletions vinvoor/src/hooks/useSettings.ts
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -11,8 +11,15 @@ export const useSettings = () =>
retry: 1,
});

export const usePatchSettings = () =>
useMutation({
export const usePatchSettings = () => {
const queryClient = useQueryClient();

return useMutation({
mutationFn: (args: Record<string, string | number | boolean>) =>
patchApi(ENDPOINT, args),
onSuccess: () =>
queryClient.invalidateQueries({
predicate: query => query.queryKey[0] !== "settings",
}),
});
};
5 changes: 4 additions & 1 deletion vinvoor/src/settings/Settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ export const Settings = () => {
<Grid item xs={6}>
<Paper elevation={4} sx={{ p: "10px" }}>
<Stack direction="row" display="flex" alignItems="center">
<Tooltip title="Season to display data for" placement="right">
<Tooltip
title="Season for which to display data for"
placement="right"
>
<HelpCircleOutline
sx={{
fontSize: "15px",
Expand Down

0 comments on commit 63873bb

Please sign in to comment.