-
-
Notifications
You must be signed in to change notification settings - Fork 7.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unliking a post updates like count on front end #12140
Conversation
when unfavouriting a status
I'm sorry, but there is a reason why an asynchronous worker is used. Yes, your code returns the real state, but does so by running a lot of tasks (including networking) within the request/response cycle. If connection drops in the middle, the unfavourite operation could miss some instructions. It would be far easier to update the favourites count in the Redux reducer on the client-side. |
Thanks for the feedback! I'll undo the changes that I made, and I'll do it on the Redux reducer side instead. |
Okay, I did it through the reducer on the client-side! Does this look better? |
@@ -37,6 +38,9 @@ export default function statuses(state = initialState, action) { | |||
return importStatuses(state, action.statuses); | |||
case FAVOURITE_REQUEST: | |||
return state.setIn([action.status.get('id'), 'favourited'], true); | |||
case UNFAVOURITE_SUCCESS: | |||
const favouritesCount = action.status.get('favourites_count'); | |||
return state.setIn([action.status.get('id'), 'favourites_count'], favouritesCount - 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A more concise way of writing this is:
return state.updateIn([action.status.get('id'), 'favourites_count'], x => Math.max(x - 1, 0));
Fixes the issue outlined by #9638.
Previous behaviour:
New behaviour: