SWR: Keep cache when mutating (#484)

This commit is contained in:
Erik Vroon
2024-02-17 14:31:07 +01:00
committed by GitHub
parent 7666e3a22b
commit 181bbe3368
22 changed files with 33 additions and 33 deletions

View File

@@ -111,7 +111,7 @@ function StageItemRow({
leftSection={<IconTrash size={rem(14)} />}
onClick={async () => {
await deleteStageItem(tournament.id, stageItem.id);
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
}}
color="red"
>
@@ -193,7 +193,7 @@ function StageColumn({
leftSection={<IconTrash size={rem(14)} />}
onClick={async () => {
await deleteStage(tournament.id, stage.id);
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
}}
color="red"
>

View File

@@ -24,7 +24,7 @@ export default function CreateStageButton({
style={{ marginRight: 10 }}
onClick={async () => {
await createStage(tournament.id);
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
}}
leftSection={<GoPlus size={24} />}
>
@@ -50,7 +50,7 @@ export function CreateStageButtonLarge({
style={{ marginRight: 10, width: '25%' }}
onClick={async () => {
await createStage(tournament.id);
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
}}
leftSection={<GoPlus size={24} />}
>

View File

@@ -59,7 +59,7 @@ export default function ClubModal({
onSubmit={form.onSubmit(async (values) => {
if (is_create_form) await createClub(values.name);
else await updateClub(club.id, values.name);
await swrClubsResponse.mutate(null);
await swrClubsResponse.mutate();
setOpened(false);
})}
>

View File

@@ -174,7 +174,7 @@ export function CreateStageItemModal({
};
});
await createStageItem(tournament.id, stage.id, values.type, teamCount, inputs);
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
})}
>
<Select

View File

@@ -35,8 +35,8 @@ function MatchDeleteButton({
fullWidth
onClick={async () => {
await deleteMatch(tournamentData.id, match.id);
await swrRoundsResponse.mutate(null);
if (swrUpcomingMatchesResponse != null) await swrUpcomingMatchesResponse.mutate(null);
await swrRoundsResponse.mutate();
if (swrUpcomingMatchesResponse != null) await swrUpcomingMatchesResponse.mutate();
}}
style={{ marginTop: '1rem' }}
size="sm"
@@ -111,8 +111,8 @@ export default function MatchModal({
custom_margin_minutes: customMarginEnabled ? values.custom_margin_minutes : null,
};
await updateMatch(tournamentData.id, match.id, updatedMatch);
await swrStagesResponse.mutate(null);
if (swrUpcomingMatchesResponse != null) await swrUpcomingMatchesResponse.mutate(null);
await swrStagesResponse.mutate();
if (swrUpcomingMatchesResponse != null) await swrUpcomingMatchesResponse.mutate();
setOpened(false);
})}
>

View File

@@ -33,7 +33,7 @@ function MultiPlayerTab({
<form
onSubmit={form.onSubmit(async (values) => {
await createMultiplePlayers(tournament_id, values.names, values.active);
await swrPlayersResponse.mutate(null);
await swrPlayersResponse.mutate();
setOpened(false);
})}
>
@@ -75,7 +75,7 @@ function SinglePlayerTab({
<form
onSubmit={form.onSubmit(async (values) => {
await createPlayer(tournament_id, values.name, values.active);
await swrPlayersResponse.mutate(null);
await swrPlayersResponse.mutate();
setOpened(false);
})}
>

View File

@@ -47,7 +47,7 @@ export default function PlayerUpdateModal({
<form
onSubmit={form.onSubmit(async (values) => {
await updatePlayer(tournament_id, player.id, values.name, values.active, null);
await swrPlayersResponse.mutate(null);
await swrPlayersResponse.mutate();
setOpened(false);
})}
>

View File

@@ -38,8 +38,8 @@ function RoundDeleteButton({
fullWidth
onClick={async () => {
await deleteRound(tournamentData.id, round.id);
await swrRoundsResponse.mutate(null);
if (swrUpcomingMatchesResponse != null) await swrUpcomingMatchesResponse.mutate(null);
await swrRoundsResponse.mutate();
if (swrUpcomingMatchesResponse != null) await swrUpcomingMatchesResponse.mutate();
}}
style={{ marginTop: '15px' }}
size="sm"
@@ -82,7 +82,7 @@ export default function RoundModal({
<form
onSubmit={form.onSubmit(async (values) => {
await updateRound(tournamentData.id, round.id, values as RoundInterface);
await swrRoundsResponse.mutate(null);
await swrRoundsResponse.mutate();
setOpened(false);
})}
>

View File

@@ -35,7 +35,7 @@ function MultiTeamTab({
<form
onSubmit={form.onSubmit(async (values) => {
await createTeams(tournament_id, values.names, values.active);
await swrTeamsResponse.mutate(null);
await swrTeamsResponse.mutate();
setOpened(false);
})}
>
@@ -79,7 +79,7 @@ function SingleTeamTab({
<form
onSubmit={form.onSubmit(async (values) => {
await createTeam(tournament_id, values.name, values.active, values.player_ids);
await swrTeamsResponse.mutate(null);
await swrTeamsResponse.mutate();
setOpened(false);
})}
>

View File

@@ -49,7 +49,7 @@ export default function TeamUpdateModal({
values.player_ids
);
if (requestSucceeded(result)) {
await swrTeamsResponse.mutate(null);
await swrTeamsResponse.mutate();
setOpened(false);
}
})}

View File

@@ -77,7 +77,7 @@ function GeneralTournamentForm({
values.duration_minutes,
values.margin_minutes
);
await swrTournamentsResponse.mutate(null);
await swrTournamentsResponse.mutate();
setOpened(false);
})}
>

View File

@@ -32,7 +32,7 @@ export function UpdateStageModal({
<form
onSubmit={form.onSubmit(async (values) => {
await updateStage(tournament.id, stage.id, values.name);
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
})}
>
<TextInput

View File

@@ -32,7 +32,7 @@ export function UpdateStageItemModal({
<form
onSubmit={form.onSubmit(async (values) => {
await updateStageItem(tournament.id, stageItem.id, values.name);
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
})}
>
<TextInput

View File

@@ -32,7 +32,7 @@ export default function ClubsTable({ swrClubsResponse }: { swrClubsResponse: SWR
<DeleteButton
onClick={async () => {
await deleteClub(club.id);
await swrClubsResponse.mutate(null);
await swrClubsResponse.mutate();
}}
title={t('delete_club_button')}
/>

View File

@@ -39,7 +39,7 @@ export default function CourtsTable({
<DeleteButton
onClick={async () => {
await deleteCourt(tournament.id, court.id);
await swrCourtsResponse.mutate(null);
await swrCourtsResponse.mutate();
}}
title={t('delete_court_button')}
/>

View File

@@ -103,7 +103,7 @@ export default function PlayersTable({
<DeleteButton
onClick={async () => {
await deletePlayer(tournamentData.id, player.id);
await swrPlayersResponse.mutate(null);
await swrPlayersResponse.mutate();
}}
title={t('delete_player_button')}
/>

View File

@@ -62,7 +62,7 @@ export default function TeamsTable({
<DeleteButton
onClick={async () => {
await deleteTeam(tournamentData.id, team.id);
await swrTeamsResponse.mutate(null);
await swrTeamsResponse.mutate();
}}
title={t('delete_team_button')}
/>

View File

@@ -57,7 +57,7 @@ export default function TournamentsTable({
<DeleteButton
onClick={async () => {
await deleteTournament(tournament.id);
await swrTournamentsResponse.mutate(null);
await swrTournamentsResponse.mutate();
}}
title={t('delete_tournament_button')}
/>

View File

@@ -50,8 +50,8 @@ export default function UpcomingMatchesTable({
await createMatch(tournamentData.id, match_to_schedule);
}
await swrRoundsResponse.mutate(null);
await swrUpcomingMatchesResponse.mutate(null);
await swrRoundsResponse.mutate();
await swrUpcomingMatchesResponse.mutate();
}
const rows = upcoming_matches

View File

@@ -25,7 +25,7 @@ function CreateCourtForm(t: Translator, tournament: Tournament, swrCourtsRespons
<form
onSubmit={form.onSubmit(async (values) => {
await createCourt(tournament.id, values.name);
await swrCourtsResponse.mutate(null);
await swrCourtsResponse.mutate();
})}
>
<Divider mt={12} />

View File

@@ -187,7 +187,7 @@ export default function SchedulePage() {
leftSection={<IconCalendarPlus size={24} />}
onClick={async () => {
await scheduleMatches(tournamentData.id);
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
}}
>
{t('schedule_description')}
@@ -205,7 +205,7 @@ export default function SchedulePage() {
new_court_id: +destination.droppableId,
new_position: destination.index,
});
await swrStagesResponse.mutate(null);
await swrStagesResponse.mutate();
}}
>
<Schedule

View File

@@ -88,7 +88,7 @@ function GeneralTournamentForm({
values.margin_minutes
);
await swrTournamentResponse.mutate(null);
await swrTournamentResponse.mutate();
})}
>
<TextInput