From c06d2ff43718af5940987e219379094f1a2de180 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 25 Jan 2020 18:19:24 +0100 Subject: [PATCH 1/4] 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 --- .../mastodon/actions/announcements.js | 21 ++++++++++++++++--- .../styles/mastodon/components.scss | 1 - 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/javascript/mastodon/actions/announcements.js b/app/javascript/mastodon/actions/announcements.js index 64bf5ef91bd..53b19a6fda0 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 e4fafc091a4..6946971cdce 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; From 90b13ffd009a431dbe98c37bc92ee59a6f0535f2 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 25 Jan 2020 19:40:36 +0100 Subject: [PATCH 2/4] =?UTF-8?q?Fix=20=E2=80=9Cnew=20items=20glow=E2=80=9D?= =?UTF-8?q?=20being=20displayed=20above=20settings=20and=20announcements?= =?UTF-8?q?=20(#12958)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mastodon/components/column_header.js | 5 ++++- .../mastodon/features/home_timeline/index.js | 3 +-- app/javascript/styles/mastodon/components.scss | 14 +++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/javascript/mastodon/components/column_header.js b/app/javascript/mastodon/components/column_header.js index 0038995c8be..ea82f9ef9d3 100644 --- a/app/javascript/mastodon/components/column_header.js +++ b/app/javascript/mastodon/components/column_header.js @@ -33,6 +33,7 @@ class ColumnHeader extends React.PureComponent { onPin: PropTypes.func, onMove: PropTypes.func, onClick: PropTypes.func, + appendContent: PropTypes.node, }; state = { @@ -81,7 +82,7 @@ class ColumnHeader extends React.PureComponent { } render () { - const { title, icon, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, placeholder } = this.props; + const { title, icon, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, placeholder, appendContent } = this.props; const { collapsed, animating } = this.state; const wrapperClassName = classNames('column-header__wrapper', { @@ -172,6 +173,8 @@ class ColumnHeader extends React.PureComponent { {(!collapsed || animating) && collapsedContent} + + {appendContent} ); diff --git a/app/javascript/mastodon/features/home_timeline/index.js b/app/javascript/mastodon/features/home_timeline/index.js index c7de8c9cbf4..2bad22bc1de 100644 --- a/app/javascript/mastodon/features/home_timeline/index.js +++ b/app/javascript/mastodon/features/home_timeline/index.js @@ -143,12 +143,11 @@ class HomeTimeline extends React.PureComponent { pinned={pinned} multiColumn={multiColumn} extraButton={announcementsButton} + appendContent={hasAnnouncements && showAnnouncements && } > - {hasAnnouncements && showAnnouncements && } - Date: Sat, 25 Jan 2020 18:19:24 +0100 Subject: [PATCH 3/4] [Glitch] Fix spurious error and incorrect state change when adding a reaction twice Port c06d2ff43718af5940987e219379094f1a2de180 to glitch-soc Signed-off-by: Thibaut Girka --- .../flavours/glitch/actions/announcements.js | 21 ++++++++++++++++--- .../styles/components/announcements.scss | 1 - 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/announcements.js b/app/javascript/flavours/glitch/actions/announcements.js index b4e8cee2f23..930493b6a86 100644 --- a/app/javascript/flavours/glitch/actions/announcements.js +++ b/app/javascript/flavours/glitch/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/flavours/glitch/styles/components/announcements.scss b/app/javascript/flavours/glitch/styles/components/announcements.scss index 6bf9e2a0cb2..00585cb1c88 100644 --- a/app/javascript/flavours/glitch/styles/components/announcements.scss +++ b/app/javascript/flavours/glitch/styles/components/announcements.scss @@ -38,7 +38,6 @@ .announcements { background: lighten($ui-base-color, 8%); - border-top: 1px solid $ui-base-color; font-size: 13px; display: flex; align-items: flex-end; From 5e4d1f699e9f2ea6954a6d2647412f98ed2ca203 Mon Sep 17 00:00:00 2001 From: ThibG Date: Sat, 25 Jan 2020 19:40:36 +0100 Subject: [PATCH 4/4] =?UTF-8?q?[Glitch]=20Fix=20=E2=80=9Cnew=20items=20glo?= =?UTF-8?q?w=E2=80=9D=20being=20displayed=20above=20settings=20and=20annou?= =?UTF-8?q?ncements?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Port 90b13ffd009a431dbe98c37bc92ee59a6f0535f2 to glitch-soc Signed-off-by: Thibaut Girka --- .../flavours/glitch/components/column_header.js | 5 ++++- .../glitch/features/home_timeline/index.js | 3 +-- .../flavours/glitch/styles/components/columns.scss | 14 +++++++++++--- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/javascript/flavours/glitch/components/column_header.js b/app/javascript/flavours/glitch/components/column_header.js index dd116242909..be45c9535e1 100644 --- a/app/javascript/flavours/glitch/components/column_header.js +++ b/app/javascript/flavours/glitch/components/column_header.js @@ -42,6 +42,7 @@ class ColumnHeader extends React.PureComponent { onMove: PropTypes.func, onClick: PropTypes.func, intl: PropTypes.object.isRequired, + appendContent: PropTypes.node, }; state = { @@ -106,7 +107,7 @@ class ColumnHeader extends React.PureComponent { } render () { - const { intl, icon, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, notifCleaning, notifCleaningActive, placeholder } = this.props; + const { intl, icon, active, children, pinned, multiColumn, extraButton, showBackButton, intl: { formatMessage }, notifCleaning, notifCleaningActive, placeholder, appendContent } = this.props; const { collapsed, animating, animatingNCD } = this.state; let title = this.props.title; @@ -229,6 +230,8 @@ class ColumnHeader extends React.PureComponent { {(!collapsed || animating) && collapsedContent} + + {appendContent} ); diff --git a/app/javascript/flavours/glitch/features/home_timeline/index.js b/app/javascript/flavours/glitch/features/home_timeline/index.js index 457ac051ce3..5e36e5f7689 100644 --- a/app/javascript/flavours/glitch/features/home_timeline/index.js +++ b/app/javascript/flavours/glitch/features/home_timeline/index.js @@ -142,12 +142,11 @@ class HomeTimeline extends React.PureComponent { pinned={pinned} multiColumn={multiColumn} extraButton={announcementsButton} + appendContent={hasAnnouncements && showAnnouncements && } > - {hasAnnouncements && showAnnouncements && } -