♻️ Update trpcs routes (#531)

This commit is contained in:
Luke Vella 2023-02-27 15:08:59 +00:00 committed by GitHub
parent d9f6a0d097
commit 18eca7cd8c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
32 changed files with 300 additions and 317 deletions

View file

@ -31,19 +31,20 @@ const Discussion: React.VoidFunctionComponent = () => {
const pollId = poll.id;
const { data: comments } = trpc.useQuery(
["polls.comments.list", { pollId }],
const { data: comments } = trpc.polls.comments.list.useQuery(
{ pollId },
{
refetchInterval: 10000, // refetch every 10 seconds
trpc: {},
},
);
const addComment = trpc.useMutation("polls.comments.add", {
const addComment = trpc.polls.comments.add.useMutation({
onSuccess: (newComment) => {
posthog.capture("created comment");
queryClient.setQueryData(
["polls.comments.list", { pollId }],
queryClient.polls.comments.list.setData(
{ pollId },
(existingComments = []) => {
return [...existingComments, newComment];
},
@ -51,10 +52,10 @@ const Discussion: React.VoidFunctionComponent = () => {
},
});
const deleteComment = trpc.useMutation("polls.comments.delete", {
const deleteComment = trpc.polls.comments.delete.useMutation({
onMutate: ({ commentId }) => {
queryClient.setQueryData(
["polls.comments.list", { pollId }],
queryClient.polls.comments.list.setData(
{ pollId },
(existingComments = []) => {
return [...existingComments].filter(({ id }) => id !== commentId);
},