Skip to content

Commit

Permalink
edit-stats: Add invalidate queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Joe2k authored and SibiAkkash committed Oct 18, 2024
1 parent 1a33fda commit 32339e6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 88 deletions.
47 changes: 15 additions & 32 deletions frontend/src/components/match/stats/EditMinStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,31 @@ const EditStats = () => {
return team?.image ?? team?.image_url;
};

const invalidateQueries = () => {
queryClient.invalidateQueries({ queryKey: ["match", params.matchId] });
queryClient.invalidateQueries({
queryKey: ["match-stats", params.matchId]
});
};

const matchStatsHalfTimeMutation = createMutation({
mutationFn: matchStatsHalfTime,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["match", params.matchId] });
}
onSuccess: invalidateQueries
});

const matchStatsFullTimeMutation = createMutation({
mutationFn: matchStatsFullTime,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["match", params.matchId] });
}
onSuccess: invalidateQueries
});

const matchStatsUndoMutation = createMutation({
mutationFn: matchStatsUndo,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["match", params.matchId] });
}
onSuccess: invalidateQueries
});

const matchStatsSwitchOffenseMutation = createMutation({
mutationFn: matchStatsSwitchOffense,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["match", params.matchId] });
}
onSuccess: invalidateQueries
});

return (
Expand Down Expand Up @@ -220,11 +219,7 @@ const EditStats = () => {
button={{ text: "Block" }}
buttonColor={matchCardColorToButtonStyles["blue"]}
disabled={matchStatsSwitchOffenseMutation.isLoading}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<BlockForm
match={matchQuery.data}
Expand Down Expand Up @@ -262,11 +257,7 @@ const EditStats = () => {
button={{ text: "Score" }}
buttonColor={matchCardColorToButtonStyles["blue"]}
disabled={matchStatsSwitchOffenseMutation.isLoading}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<ScoreForm
match={matchQuery.data}
Expand Down Expand Up @@ -295,11 +286,7 @@ const EditStats = () => {
button={{ text: "Block" }}
buttonColor={matchCardColorToButtonStyles["green"]}
disabled={matchStatsSwitchOffenseMutation.isLoading}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<BlockForm
match={matchQuery.data}
Expand Down Expand Up @@ -337,11 +324,7 @@ const EditStats = () => {
button={{ text: "Score" }}
buttonColor={matchCardColorToButtonStyles["green"]}
disabled={matchStatsSwitchOffenseMutation.isLoading}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<ScoreForm
match={matchQuery.data}
Expand Down
75 changes: 19 additions & 56 deletions frontend/src/components/match/stats/EditStats.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ const EditStats = () => {
}
);

const invalidateQueries = () => {
queryClient.invalidateQueries({ queryKey: ["match", params.matchId] });
queryClient.invalidateQueries({
queryKey: ["match-stats", params.matchId]
});
};

createEffect(() => {
if (matchStatsQuery.isSuccess && matchStatsQuery.data) {
if (matchStatsQuery.data.status !== "COM") {
Expand All @@ -67,16 +74,12 @@ const EditStats = () => {

const matchStatsHalfTimeMutation = createMutation({
mutationFn: matchStatsHalfTime,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["match", params.matchId] });
}
onSuccess: invalidateQueries
});

const matchStatsFullTimeMutation = createMutation({
mutationFn: matchStatsFullTime,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ["match", params.matchId] });
}
onSuccess: invalidateQueries
});

return (
Expand Down Expand Up @@ -236,11 +239,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Select Line", icon: userGroup }}
buttonColor={matchCardColorToButtonStyles["blue"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<SelectLineForm
match={matchQuery.data}
Expand All @@ -265,11 +264,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Block" }}
buttonColor={matchCardColorToButtonStyles["blue"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<BlockForm
match={matchQuery.data}
Expand All @@ -284,11 +279,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Score" }}
buttonColor={matchCardColorToButtonStyles["blue"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<ScoreForm
match={matchQuery.data}
Expand All @@ -299,11 +290,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Drop" }}
buttonColor={matchCardColorToButtonStyles["blue"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<DropForm
match={matchQuery.data}
Expand All @@ -314,11 +301,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Throwaway" }}
buttonColor={matchCardColorToButtonStyles["blue"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<ThrowawayForm
match={matchQuery.data}
Expand Down Expand Up @@ -346,11 +329,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Select Line", icon: userGroup }}
buttonColor={matchCardColorToButtonStyles["green"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<SelectLineForm
match={matchQuery.data}
Expand All @@ -375,11 +354,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Block" }}
buttonColor={matchCardColorToButtonStyles["green"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<BlockForm
match={matchQuery.data}
Expand All @@ -394,11 +369,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Score" }}
buttonColor={matchCardColorToButtonStyles["green"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<ScoreForm
match={matchQuery.data}
Expand All @@ -409,11 +380,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Drop" }}
buttonColor={matchCardColorToButtonStyles["green"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<DropForm
match={matchQuery.data}
Expand All @@ -424,11 +391,7 @@ const EditStats = () => {
<ButtonWithModal
button={{ text: "Throwaway" }}
buttonColor={matchCardColorToButtonStyles["green"]}
onClose={() => {
queryClient.invalidateQueries({
queryKey: ["match", params.matchId]
});
}}
onClose={invalidateQueries}
>
<ThrowawayForm
match={matchQuery.data}
Expand Down

0 comments on commit 32339e6

Please sign in to comment.