[Glitch] Fix spurious error and incorrect state change when adding a reaction twice
Port c06d2ff437
to glitch-soc
Signed-off-by: Thibaut Girka <thib@sitedethib.com>
remotes/1727458204337373841/tmp_refs/heads/signup-info-prompt
parent
3d9310bf3f
commit
98d5ab6be9
|
@ -56,12 +56,27 @@ export const updateAnnouncements = announcement => ({
|
||||||
});
|
});
|
||||||
|
|
||||||
export const addReaction = (announcementId, name) => (dispatch, getState) => {
|
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(() => {
|
api(getState).put(`/api/v1/announcements/${announcementId}/reactions/${name}`).then(() => {
|
||||||
dispatch(addReactionSuccess(announcementId, name));
|
dispatch(addReactionSuccess(announcementId, name, alreadyAdded));
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
dispatch(addReactionFail(announcementId, name, err));
|
if (!alreadyAdded) {
|
||||||
|
dispatch(addReactionFail(announcementId, name, err));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,6 @@
|
||||||
|
|
||||||
.announcements {
|
.announcements {
|
||||||
background: lighten($ui-base-color, 8%);
|
background: lighten($ui-base-color, 8%);
|
||||||
border-top: 1px solid $ui-base-color;
|
|
||||||
font-size: 13px;
|
font-size: 13px;
|
||||||
display: flex;
|
display: flex;
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
|
|
Loading…
Reference in New Issue