🐛 Fix race condition (#1625)

This commit is contained in:
Luke Vella 2025-03-10 10:36:34 +00:00 committed by GitHub
parent e777e673a3
commit dd719620ff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 14 deletions

View file

@ -69,13 +69,6 @@ export const CreatePoll: React.FunctionComponent = () => {
const posthog = usePostHog();
const createPoll = trpc.polls.create.useMutation({
networkMode: "always",
onMutate: async () => {
if (session.status !== "authenticated") {
await signIn("guest", {
redirect: false,
});
}
},
onError: (error) => {
if (error.data?.code === "BAD_REQUEST") {
toast({
@ -91,6 +84,11 @@ export const CreatePoll: React.FunctionComponent = () => {
<form
onSubmit={form.handleSubmit(async (formData) => {
const title = required(formData?.title);
if (session.status !== "authenticated") {
await signIn("guest", {
redirect: false,
});
}
await createPoll.mutateAsync(
{
title: title,

View file

@ -84,13 +84,6 @@ function NewCommentForm({
const { toast } = useToast();
const addComment = trpc.polls.comments.add.useMutation({
onMutate: async () => {
if (session.status !== "authenticated") {
await signIn("guest", {
redirect: false,
});
}
},
onSuccess: () => {
posthog?.capture("created comment");
},
@ -105,6 +98,11 @@ function NewCommentForm({
<form
className="w-full space-y-2.5"
onSubmit={handleSubmit(async ({ authorName, content }) => {
if (session.status !== "authenticated") {
await signIn("guest", {
redirect: false,
});
}
await addComment.mutateAsync({ authorName, content, pollId });
reset({ authorName, content: "" });
onSubmit?.();