Skip to content
Snippets Groups Projects
Unverified Commit 858d0dd1 authored by ThibG's avatar ThibG Committed by GitHub
Browse files

Fix frontend crash when deleting announcements (#13312)

Refactor and fix #13283, which only worked in some cases.
parent beb80adb
No related branches found
No related tags found
No related merge requests found
...@@ -378,6 +378,14 @@ class Announcements extends ImmutablePureComponent { ...@@ -378,6 +378,14 @@ class Announcements extends ImmutablePureComponent {
index: 0, 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 () { componentDidMount () {
this._markAnnouncementAsRead(); this._markAnnouncementAsRead();
} }
...@@ -389,7 +397,7 @@ class Announcements extends ImmutablePureComponent { ...@@ -389,7 +397,7 @@ class Announcements extends ImmutablePureComponent {
_markAnnouncementAsRead () { _markAnnouncementAsRead () {
const { dismissAnnouncement, announcements } = this.props; const { dismissAnnouncement, announcements } = this.props;
const { index } = this.state; 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')); if (!announcement.get('read')) dismissAnnouncement(announcement.get('id'));
} }
...@@ -407,7 +415,7 @@ class Announcements extends ImmutablePureComponent { ...@@ -407,7 +415,7 @@ class Announcements extends ImmutablePureComponent {
render () { render () {
const { announcements, intl } = this.props; 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()) { if (announcements.isEmpty()) {
return null; return null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment