diff options
author | ThibG <thib@sitedethib.com> | 2020-03-28 15:19:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-28 15:19:05 +0100 |
commit | a192b193bdf7013df09c6cd63916274cd9d47cf7 (patch) | |
tree | 413de2a72a6f3a126e19e12178524ca33c27e436 /app/javascript/flavours/glitch/features/getting_started | |
parent | 02f1c04fabab221130de8dfb5611be81825b193b (diff) | |
parent | d98fabf2ee44c2c25775066abda46552ab05993e (diff) |
Merge pull request #1308 from ThibG/glitch-soc/merge-upstream
Merge upstream changes
Diffstat (limited to 'app/javascript/flavours/glitch/features/getting_started')
-rw-r--r-- | app/javascript/flavours/glitch/features/getting_started/components/announcements.js | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/app/javascript/flavours/glitch/features/getting_started/components/announcements.js b/app/javascript/flavours/glitch/features/getting_started/components/announcements.js index 5f6e6d84c..acaa78fe3 100644 --- a/app/javascript/flavours/glitch/features/getting_started/components/announcements.js +++ b/app/javascript/flavours/glitch/features/getting_started/components/announcements.js @@ -378,6 +378,14 @@ class Announcements extends ImmutablePureComponent { index: 0, }; + static getDerivedStateFromProps(props, state) { + if (props.announcements.size > 0 && state.index >= props.announcements.size) { + return { index: props.announcements.size - 1 }; + } else { + return null; + } + } + componentDidMount () { this._markAnnouncementAsRead(); } @@ -389,7 +397,7 @@ class Announcements extends ImmutablePureComponent { _markAnnouncementAsRead () { const { dismissAnnouncement, announcements } = this.props; const { index } = this.state; - const announcement = announcements.get(index) || announcements.get(index - 1); + const announcement = announcements.get(index); if (!announcement.get('read')) dismissAnnouncement(announcement.get('id')); } @@ -407,7 +415,7 @@ class Announcements extends ImmutablePureComponent { render () { const { announcements, intl } = this.props; - const index = this.state.index < announcements.size ? this.state.index : announcements.size - 1; + const { index } = this.state; if (announcements.isEmpty()) { return null; |