From ad1d4a8bfa098db7e91af596d91d0cf577c1a7f9 Mon Sep 17 00:00:00 2001 From: Kevin Duong Date: Thu, 27 Aug 2026 18:07:56 -0400 Subject: [PATCH 1/5] fix(app): Close downvote dialog before it switches to "submitted" state --- app/src/lib/useVote.ts | 17 +++++++++++++---- app/src/routes/guides/$slug/index.tsx | 2 +- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/src/lib/useVote.ts b/app/src/lib/useVote.ts index 71325b4a..a1aa28d8 100644 --- a/app/src/lib/useVote.ts +++ b/app/src/lib/useVote.ts @@ -56,7 +56,8 @@ export function useVote( // leaves the buttons showing something that was not stored. const mutate = async ( run: (id: string) => Promise, - failure: string + failure: string, + onSuccess?: () => void ) => { if (!variantId) return false; if (!userId) { @@ -66,7 +67,10 @@ export function useVote( setSubmitting(true); try { - setVote(await run(variantId)); + const submission = await run(variantId); + setVote(submission); + onSuccess?.(); + await loadTally(variantId); return true; } catch { @@ -86,10 +90,15 @@ export function useVote( return castVote(id, { direction: "up" }); }, "Could not save your vote."); - const downvote = (reason: DownvoteReason, note: string) => + const downvote = ( + reason: DownvoteReason, + note: string, + onSuccess?: () => void + ) => mutate( (id) => castVote(id, { direction: "down", reason, note: note || null }), - "Could not save your downvote." + "Could not save your downvote.", + onSuccess ); const removeVote = () => diff --git a/app/src/routes/guides/$slug/index.tsx b/app/src/routes/guides/$slug/index.tsx index 449bcb3e..879b71cf 100644 --- a/app/src/routes/guides/$slug/index.tsx +++ b/app/src/routes/guides/$slug/index.tsx @@ -184,7 +184,7 @@ function RouteComponent() { : null } onSubmit={async (reason, note) => { - if (await downvote(reason, note)) setDownvoteOpen(false); + await downvote(reason, note, () => setDownvoteOpen(false)); }} onRemove={async () => { if (await removeVote()) setDownvoteOpen(false); From e368f3eb1fce87a01cba69ab2b905de84cc22234 Mon Sep 17 00:00:00 2001 From: Kevin Duong Date: Thu, 27 Aug 2026 18:27:05 -0400 Subject: [PATCH 2/5] fix(app): Close downvote dialog before it switches to "unsubmitted" state when user deletes vote --- app/src/lib/useVote.ts | 14 +++++++++----- app/src/routes/guides/$slug/index.tsx | 6 ++++-- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/app/src/lib/useVote.ts b/app/src/lib/useVote.ts index a1aa28d8..63612e28 100644 --- a/app/src/lib/useVote.ts +++ b/app/src/lib/useVote.ts @@ -101,11 +101,15 @@ export function useVote( onSuccess ); - const removeVote = () => - mutate(async (id) => { - await retractVote(id); - return null; - }, "Could not remove your vote."); + const removeVote = (onSuccess: () => void) => + mutate( + async (id) => { + await retractVote(id); + return null; + }, + "Could not remove your vote.", + onSuccess + ); return { vote, tally, submitting, upvote, downvote, removeVote }; } diff --git a/app/src/routes/guides/$slug/index.tsx b/app/src/routes/guides/$slug/index.tsx index 879b71cf..1d05aa4d 100644 --- a/app/src/routes/guides/$slug/index.tsx +++ b/app/src/routes/guides/$slug/index.tsx @@ -184,10 +184,12 @@ function RouteComponent() { : null } onSubmit={async (reason, note) => { - await downvote(reason, note, () => setDownvoteOpen(false)); + await downvote(reason, note, async () => + setDownvoteOpen(false) + ); }} onRemove={async () => { - if (await removeVote()) setDownvoteOpen(false); + await removeVote(() => setDownvoteOpen(false)); }} /> From 6c0efe3f9f320ba55a3b0a709254a87a6c7259f6 Mon Sep 17 00:00:00 2001 From: Kevin Duong Date: Tue, 1 Sep 2026 14:26:17 -0400 Subject: [PATCH 3/5] fix(app): Change state after DownvoteDialog closes --- app/src/lib/useVote.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/src/lib/useVote.ts b/app/src/lib/useVote.ts index 63612e28..62fe58d2 100644 --- a/app/src/lib/useVote.ts +++ b/app/src/lib/useVote.ts @@ -68,9 +68,15 @@ export function useVote( setSubmitting(true); try { const submission = await run(variantId); - setVote(submission); + onSuccess?.(); + const delay = (ms: number) => + new Promise((resolve) => setTimeout(resolve, ms)); + await delay(200); + + setVote(submission); + await loadTally(variantId); return true; } catch { From 5dd9c004769f2bf150cf5091dc5f4981c9a1f33e Mon Sep 17 00:00:00 2001 From: Kevin Duong Date: Tue, 1 Sep 2026 14:27:49 -0400 Subject: [PATCH 4/5] style(app): Rename `onSuccess` to `handleClose` for clarity --- app/src/lib/useVote.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/src/lib/useVote.ts b/app/src/lib/useVote.ts index 62fe58d2..4a9b171d 100644 --- a/app/src/lib/useVote.ts +++ b/app/src/lib/useVote.ts @@ -57,7 +57,7 @@ export function useVote( const mutate = async ( run: (id: string) => Promise, failure: string, - onSuccess?: () => void + handleClose?: () => void ) => { if (!variantId) return false; if (!userId) { @@ -69,7 +69,7 @@ export function useVote( try { const submission = await run(variantId); - onSuccess?.(); + handleClose?.(); const delay = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)); @@ -99,22 +99,22 @@ export function useVote( const downvote = ( reason: DownvoteReason, note: string, - onSuccess?: () => void + handleClose?: () => void ) => mutate( (id) => castVote(id, { direction: "down", reason, note: note || null }), "Could not save your downvote.", - onSuccess + handleClose ); - const removeVote = (onSuccess: () => void) => + const removeVote = (handleClose: () => void) => mutate( async (id) => { await retractVote(id); return null; }, "Could not remove your vote.", - onSuccess + handleClose ); return { vote, tally, submitting, upvote, downvote, removeVote }; From 3e85a7d346171b3a88e8f5cce15b691396ee7c76 Mon Sep 17 00:00:00 2001 From: Kevin Duong Date: Tue, 1 Sep 2026 20:02:50 -0400 Subject: [PATCH 5/5] fix(app): Add missing argument to function call --- app/src/routes/guides/$slug/$variantSlug/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/routes/guides/$slug/$variantSlug/index.tsx b/app/src/routes/guides/$slug/$variantSlug/index.tsx index b19b14e8..fc6799c6 100644 --- a/app/src/routes/guides/$slug/$variantSlug/index.tsx +++ b/app/src/routes/guides/$slug/$variantSlug/index.tsx @@ -195,7 +195,7 @@ function RouteComponent() { if (await downvote(reason, note)) setDownvoteOpen(false); }} onRemove={async () => { - if (await removeVote()) setDownvoteOpen(false); + await removeVote(() => setDownvoteOpen(false)); }} />