From 41e3ab1c70fb628436ce1d25c62de11c368130c5 Mon Sep 17 00:00:00 2001
From: Nicholas Zuber
{ - this.props.notificationsApi.fetchNotificationsSync(); + this.props.notificationsApi.fetchNotificationsSync() + .catch(error => this.setState({error})); this.setState({currentTime: moment()}); }, 8 * 1000); } @@ -327,7 +329,6 @@ class NotificationsPage extends React.Component { // we shouldn't do it like this. instead, we should have an additional state called // "new changes" or something that the notifications api knows about. // this will be whatever we get in the syncing/fetching response - console.log('send', this.props.notificationsApi.newChanges) this.sendWebNotification(this.props.notificationsApi.newChanges); } @@ -412,7 +413,7 @@ class NotificationsPage extends React.Component { onRefreshNotifications={this.props.storageApi.refreshNotifications} isSearching={this.state.isSearching} isFetchingNotifications={isFetchingNotifications} - fetchingNotificationsError={fetchingNotificationsError} + fetchingNotificationsError={fetchingNotificationsError || this.state.error} onSetActiveFilter={this.onSetActiveFilter} /> ); diff --git a/src/providers/Notifications.js b/src/providers/Notifications.js index 424215e..500aa05 100644 --- a/src/providers/Notifications.js +++ b/src/providers/Notifications.js @@ -119,22 +119,6 @@ class NotificationsProvider extends React.Component { this.last_modified = headers['last-modified']; } - return { - headers, - json - }; - }); - } - - requestFetchNotifications = (page = 1, optimizePolling = true) => { - if (this.state.syncing) { - // Don't try to send off another request if we're already trying to get one. - return Promise.reject(); - } - - this.setState({syncing: true}); - return this.requestPage(page, optimizePolling) - .then(({headers, json}) => { // This means that we got a response where nothing changed. if (json === null) { this.setState({newChanges: null}); @@ -146,7 +130,17 @@ class NotificationsProvider extends React.Component { nextPage = links.next.page; } return this.processNotificationsChunk(nextPage, json); - }) + }); + } + + requestFetchNotifications = (page = 1, optimizePolling = true) => { + if (this.state.syncing) { + // Don't try to send off another request if we're already trying to get one. + return Promise.reject(); + } + + this.setState({syncing: true}); + return this.requestPage(page, optimizePolling) .finally(() => this.setState({syncing: false})); } @@ -206,11 +200,11 @@ class NotificationsProvider extends React.Component { if (nextPage && everythingUpdated) { // Still need to fetch more updates. - this.fetchNotifications(nextPage, false); + return this.requestPage(nextPage, false).then(resolve); } else { // All done fetching updates, let's trigger a sync. this.props.refreshNotifications(); - resolve(); + return resolve(); } }); }