Skip to content

Sync vote state between feed and comments - #95

Open
FrankBStack wants to merge 2 commits into
micahlt:mainfrom
FrankBStack:fix/vote-state-sync
Open

Sync vote state between feed and comments#95
FrankBStack wants to merge 2 commits into
micahlt:mainfrom
FrankBStack:fix/vote-state-sync

Conversation

@FrankBStack

@FrankBStack FrankBStack commented Sep 6, 2026

Copy link
Copy Markdown

Repro: upvote a post from the comments screen, go back to the feed. The card still looks unvoted. Tap the arrow and it lights up but the count doesn't move, because it just re-sent the same vote.

Cause: every Post/Comment keeps its own copy of vote_status / vote_total from whatever object it was handed, so two cards for the same post drift apart.

Fix: a tiny in-memory store keyed by post/comment id (src/utils/voteStore.js). Cards read from it, subscribe to changes, and publish the server response after a vote, so feed, comments, profile tabs and quote posts all agree. Pull-to-refresh on the feed clears it since the server data is fresher at that point.

Also makes the count update optimistically on tap. Removing a vote on a comment comes back from the server with the old vote_total, which left the number stuck after the arrow lost its colour. The server total is now only accepted when it actually reflects the action, and a failed request rolls back.

Each Post/Comment kept its own copy of vote_status/vote_total, so voting
on the comments screen left the feed card stale and tapping it again just
re-sent the same vote. Added a small shared vote store keyed by id that
cards subscribe to. Pull-to-refresh clears it.
Removing a vote on a comment comes back with vote_status cleared but the
old vote_total, so the arrow lost its colour and the number stayed put.
Apply the delta locally as soon as the arrow is tapped, then only accept
the server's total if it actually reflects the action. Roll back if the
request fails.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant