]> cat aescling's git repositories - mastodon.git/commitdiff
Fix spurious error and incorrect state change when adding a reaction twice (#12957)
authorThibG <thib@sitedethib.com>
Sat, 25 Jan 2020 17:19:24 +0000 (18:19 +0100)
committerEugen Rochko <eugen@zeonfederated.com>
Sat, 25 Jan 2020 17:19:24 +0000 (18:19 +0100)
* Fix spurious error and incorrect state change when adding a reaction twice

* Remove superfluous top border for announcements box

app/javascript/mastodon/actions/announcements.js
app/javascript/styles/mastodon/components.scss

index 64bf5ef91bdc635f9042469f6d3da2141714f3b4..53b19a6fda07c0e4bf596da108fb5517099e7f4c 100644 (file)
@@ -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));
+    }
   });
 };
 
index e4fafc091a401c3c4a8072dd6a919f8759a41ab3..6946971cdce75860a9f75a88bd4df2996ab3fe4f 100644 (file)
@@ -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;