Skip to content

Commit

Permalink
⚡️ Quicker UI updates when adding participant
Browse files Browse the repository at this point in the history
  • Loading branch information
lukevella committed Mar 2, 2024
1 parent f9d5d0a commit d0f12d9
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion apps/web/src/components/poll/mutations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit d0f12d9

Please sign in to comment.