Sync vote state between feed and comments - #95
Open
FrankBStack wants to merge 2 commits into
Open
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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/Commentkeeps its own copy ofvote_status/vote_totalfrom 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.