Disable edit vote button when mutation loading

This commit is contained in:
Kalle (Sendou)
2021-04-23 09:43:36 +03:00
parent afebf16f1d
commit 4831a4a13c
3 changed files with 18 additions and 12 deletions

View File

@@ -8,10 +8,12 @@ export function ChangeVoteButtons({
score,
isSameRegion,
editVote,
isLoadingMutation,
}: {
score: number;
isSameRegion: boolean;
editVote: (score: number) => void;
isLoadingMutation: boolean;
}) {
const [editing, setEditing] = useState(false);
const [currentScore, setCurrentScore] = useState(score);
@@ -48,6 +50,7 @@ export function ChangeVoteButtons({
editVote(currentScore);
setEditing(false);
}}
disabled={isLoadingMutation}
>
Save
</Button>

View File

@@ -88,18 +88,18 @@ export default function usePlusVoting() {
},
}
);
const { mutate: editVoteMutate, status: editVoteStatus } = trpc.useMutation(
"plus.editVote",
{
onSuccess() {
toast(getToastOptions("Successfully edited vote", "success"));
utils.invalidateQuery(["plus.votedUserScores"]);
},
onError(error) {
toast(getToastOptions(error.message, "error"));
},
}
);
const {
mutate: editVoteMutate,
isLoading: isLoadingEditVote,
} = trpc.useMutation("plus.editVote", {
onSuccess() {
toast(getToastOptions("Successfully edited vote", "success"));
utils.invalidateQuery(["plus.votedUserScores"]);
},
onError(error) {
toast(getToastOptions(error.message, "error"));
},
});
const ownPlusStatus = statuses?.find((status) => status.user.id === user?.id);
@@ -145,5 +145,6 @@ export default function usePlusVoting() {
voteStatus,
votedUsers: getVotedUsers(),
editVote: editVoteMutate,
isLoadingEditVote,
};
}

View File

@@ -30,6 +30,7 @@ export default function PlusVotingPage() {
voteStatus,
votedUsers,
editVote,
isLoadingEditVote,
} = usePlusVoting();
useEffect(() => {
@@ -68,6 +69,7 @@ export default function PlusVotingPage() {
editVote={(score) =>
editVote({ userId: votedUser.userId, score })
}
isLoadingMutation={isLoadingEditVote}
/>
</Fragment>
);