️ Quicker UI updates when adding participant (#1045)

This commit is contained in:
Luke Vella 2024-03-02 14:43:25 +05:30 committed by GitHub
parent f9d5d0a9bc
commit fe856d6c7d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -19,7 +19,17 @@ export const useAddParticipantMutation = () => {
const queryClient = trpc.useUtils();
return trpc.polls.participants.add.useMutation({
onSuccess: (_, { pollId, name, email }) => {
onSuccess: (newParticipant, input) => {
const { pollId, name, email } = newParticipant;
queryClient.polls.participants.list.setData(
{ pollId },
(existingParticipants = []) => {
return [
{ ...newParticipant, votes: input.votes },
...existingParticipants,
];
},
);
queryClient.polls.participants.list.invalidate({ pollId });
posthog?.capture("add participant", {
pollId,