about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-01-25 18:19:24 +0100
committerEugen Rochko <eugen@zeonfederated.com>2020-01-25 18:19:24 +0100
commitc06d2ff43718af5940987e219379094f1a2de180 (patch)
tree173bbaf7e42eb7326c4ca9a4e48d345588d9b3ec /app
parent48c55b6392661cde8e28cf076c3d132c22d17a0f (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')
-rw-r--r--app/javascript/mastodon/actions/announcements.js21
-rw-r--r--app/javascript/styles/mastodon/components.scss1
2 files changed, 18 insertions, 4 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));
+    }
   });
 };
 
diff --git a/app/javascript/styles/mastodon/components.scss b/app/javascript/styles/mastodon/components.scss
index e4fafc091..6946971cd 100644
--- a/app/javascript/styles/mastodon/components.scss
+++ b/app/javascript/styles/mastodon/components.scss
@@ -6632,7 +6632,6 @@ noscript {
 
 .announcements {
   background: lighten($ui-base-color, 8%);
-  border-top: 1px solid $ui-base-color;
   font-size: 13px;
   display: flex;
   align-items: flex-end;