From 12963342bb616d46393e5a68702a85d650b3e395 Mon Sep 17 00:00:00 2001 From: root Date: Mon, 6 Apr 2026 21:45:29 +0500 Subject: [PATCH] fix: update votedBooks state immediately on swipe so history drawer isn't empty doAction() was fire-and-forgetting the POST but never updating the client-side votedBooks array. History was only populated from SSR data.votedBooks (loaded at page init), so any votes cast during the current session were invisible in the drawer until a full page reload. Now we prepend/replace an entry in votedBooks optimistically the moment a swipe action fires. --- ui/src/routes/discover/+page.svelte | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ui/src/routes/discover/+page.svelte b/ui/src/routes/discover/+page.svelte index 935be27..342c7f6 100644 --- a/ui/src/routes/discover/+page.svelte +++ b/ui/src/routes/discover/+page.svelte @@ -239,6 +239,16 @@ body: JSON.stringify({ slug: book.slug, action }) }); + // Optimistically add/update the history list so the drawer shows it immediately. + // If this slug was already voted (e.g. swiped twice via undo+re-swipe), replace it. + const existing = votedBooks.findIndex((v) => v.slug === book.slug); + const entry: VotedBook = { slug: book.slug, action, votedAt: new Date().toISOString(), book }; + if (existing !== -1) { + votedBooks = [entry, ...votedBooks.filter((_, i) => i !== existing)]; + } else { + votedBooks = [entry, ...votedBooks]; + } + // Fly out transitioning = true; const target = flyTargets[action];