Skip to content

Unliking a post updates like count on front end#12140

Merged
Gargron merged 7 commits intomastodon:masterfrom
NimaBoscarino:master
Oct 24, 2019
Merged

Unliking a post updates like count on front end#12140
Gargron merged 7 commits intomastodon:masterfrom
NimaBoscarino:master

Conversation

@NimaBoscarino
Copy link
Copy Markdown
Contributor

Fixes the issue outlined by #9638.

Previous behaviour:

New behaviour:

@Gargron
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Contributor Author

Okay, I did it through the reducer on the client-side! Does this look better?

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
Copy Markdown
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