Skip to content
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

Merged
merged 7 commits into from
Oct 24, 2019
Merged

Unliking a post updates like count on front end #12140

merged 7 commits into from
Oct 24, 2019

Conversation

NimaBoscarino
Copy link
Contributor

Fixes the issue outlined by #9638.

Previous behaviour:

New behaviour:

@Gargron
Copy link
Member

Gargron commented Oct 10, 2019

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.

@NimaBoscarino
Copy link
Contributor Author

Thanks for the feedback! I'll undo the changes that I made, and I'll do it on the Redux reducer side instead.

@NimaBoscarino
Copy link
Contributor Author

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);
Copy link
Member

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));

@Gargron Gargron merged commit a9530e2 into mastodon:master Oct 24, 2019
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.

2 participants