diff options
author | ThibG <thib@sitedethib.com> | 2020-01-25 18:19:24 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2020-01-25 18:19:24 +0100 |
commit | c06d2ff43718af5940987e219379094f1a2de180 (patch) | |
tree | 173bbaf7e42eb7326c4ca9a4e48d345588d9b3ec /app/javascript/mastodon/actions | |
parent | 48c55b6392661cde8e28cf076c3d132c22d17a0f (diff) |
Fix spurious error and incorrect state change when adding a reaction twice (#12957)
* Fix spurious error and incorrect state change when adding a reaction twice * Remove superfluous top border for announcements box
Diffstat (limited to 'app/javascript/mastodon/actions')
-rw-r--r-- | app/javascript/mastodon/actions/announcements.js | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/app/javascript/mastodon/actions/announcements.js b/app/javascript/mastodon/actions/announcements.js index 64bf5ef91..53b19a6fd 100644 --- a/app/javascript/mastodon/actions/announcements.js +++ b/app/javascript/mastodon/actions/announcements.js @@ -56,12 +56,27 @@ export const updateAnnouncements = announcement => ({ }); export const addReaction = (announcementId, name) => (dispatch, getState) => { - dispatch(addReactionRequest(announcementId, name)); + const announcement = getState().getIn(['announcements', 'items']).find(x => x.get('id') === announcementId); + + let alreadyAdded = false; + + if (announcement) { + const reaction = announcement.get('reactions').find(x => x.get('name') === name); + if (reaction && reaction.get('me')) { + alreadyAdded = true; + } + } + + if (!alreadyAdded) { + dispatch(addReactionRequest(announcementId, name, alreadyAdded)); + } api(getState).put(`/api/v1/announcements/${announcementId}/reactions/${name}`).then(() => { - dispatch(addReactionSuccess(announcementId, name)); + dispatch(addReactionSuccess(announcementId, name, alreadyAdded)); }).catch(err => { - dispatch(addReactionFail(announcementId, name, err)); + if (!alreadyAdded) { + dispatch(addReactionFail(announcementId, name, err)); + } }); }; |