Skip to content

Commit 10b386f

Browse files
committed
issue #1985 - simplified version of NotificationsReader - marks notifications as read only on mount. It works faster and still covers all current use-cases.
1 parent 0520782 commit 10b386f

File tree

5 files changed

+5
-94
lines changed

5 files changed

+5
-94
lines changed

src/components/NotificationsReader/NotificationsReader.jsx

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,13 @@
77
import React from 'react'
88
import PT from 'prop-types'
99
import { connect } from 'react-redux'
10-
import { startReadingNotifications, stopReadingNotifications } from '../../routes/notifications/actions'
10+
import { markNotificationsReadByCriteria } from '../../routes/notifications/actions'
1111

1212
class NotificationsReader extends React.Component {
13-
constructor(props) {
14-
super(props)
15-
16-
this.notificationsReaderUid = null
17-
}
18-
1913
componentWillMount() {
20-
const { id, criteria, startReadingNotifications } = this.props
21-
22-
this.notificationsReaderUid = startReadingNotifications(criteria, id)
23-
}
24-
25-
componentWillUnmount() {
26-
const { stopReadingNotifications } = this.props
14+
const { criteria } = this.props
2715

28-
stopReadingNotifications(this.notificationsReaderUid)
16+
markNotificationsReadByCriteria(criteria)
2917
}
3018

3119
render() {
@@ -43,8 +31,7 @@ NotificationsReader.propTypes = {
4331
const mapStateToProps = () => ({})
4432

4533
const mapDispatchToProps = {
46-
startReadingNotifications,
47-
stopReadingNotifications,
34+
markNotificationsReadByCriteria,
4835
}
4936

5037
export default connect(mapStateToProps, mapDispatchToProps)(NotificationsReader)

src/config/constants.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ export const HIDE_OLDER_NOTIFICATIONS_SUCCESS = 'HIDE_OLDER_NOTIFICATIONS_SUCCES
2121
export const NOTIFICATIONS_PENDING = 'NOTIFICATIONS_PENDING'
2222
export const TOGGLE_NOTIFICATIONS_DROPDOWN_MOBILE = 'TOGGLE_NOTIFICATIONS_DROPDOWN_MOBILE'
2323
export const TOGGLE_NOTIFICATIONS_DROPDOWN_WEB = 'TOGGLE_NOTIFICATIONS_DROPDOWN_WEB'
24-
export const START_READING_NOTIFICATIONS = 'START_READING_NOTIFICATIONS'
25-
export const STOP_READING_NOTIFICATIONS = 'STOP_READING_NOTIFICATIONS'
2624
export const MARK_NOTIFICATIONS_READ = 'MARK_NOTIFICATIONS_READ'
2725

2826
// Settings

src/projects/detail/containers/FeedContainer.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,6 @@ class FeedView extends React.Component {
8585
window.removeEventListener('beforeunload', this.onLeave)
8686
}
8787

88-
shouldComponentUpdate(nextProps) {
89-
console.warn('shouldComponentUpdate')
90-
}
91-
9288
// Notify user if they navigate away while the form is modified.
9389
onLeave(e = {}) {
9490
if (this.isChanged()) {
@@ -370,7 +366,6 @@ class FeedView extends React.Component {
370366
}
371367

372368
render () {
373-
console.warn('FeedContainer render')
374369
const {currentUser, currentMemberRole, isCreatingFeed, error, allMembers,
375370
toggleNotificationRead, notifications, project, isSuperUser } = this.props
376371
const { feeds, isNewPostMobileOpen, fullscreenFeedId } = this.state

src/routes/notifications/actions/index.js

Lines changed: 1 addition & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@ import {
1515
NOTIFICATIONS_PENDING,
1616
TOGGLE_NOTIFICATIONS_DROPDOWN_MOBILE,
1717
TOGGLE_NOTIFICATIONS_DROPDOWN_WEB,
18-
START_READING_NOTIFICATIONS,
19-
STOP_READING_NOTIFICATIONS,
2018
MARK_NOTIFICATIONS_READ,
2119
} from '../../../config/constants'
2220
import notificationsService from '../services/notifications.js'
@@ -165,52 +163,4 @@ export const markNotificationsRead = (notificationIds) => (dispatch) => {
165163
}).catch(err => {
166164
Alert.error(`Failed to mark notification read. ${err.message}`)
167165
})
168-
}
169-
170-
/**
171-
* After this action is performed all notification which met the provided criteria
172-
* will be marked as read.
173-
* New notifications which are loaded will be also marked as read if met the provided criteria.
174-
*
175-
* @param {Object|Array} criteria rules or list of rules for notifications which has to be marked as read
176-
*
177-
* @returns {String} this action returns uid which can be used to stop reading notifications
178-
*/
179-
export const startReadingNotifications = (criteria, id) => (dispatch, getState) => {
180-
// if custom id was provided, make sure it's unique
181-
if (id) {
182-
const existentReader = _.get(getState(), `notifications.readers[${id}]`)
183-
184-
if (existentReader) {
185-
console.warn(`Notification reader with id '${id}' is already registered.`)
186-
return null
187-
}
188-
}
189-
190-
// if id wasn't provided, generate unique id
191-
const uid = id ? id : _.uniqueId('reader-')
192-
193-
dispatch({
194-
type: START_READING_NOTIFICATIONS,
195-
payload: {
196-
uid,
197-
criteria,
198-
}
199-
})
200-
201-
markNotificationsReadByCriteria(criteria)(dispatch, getState)
202-
203-
return uid
204-
}
205-
206-
/**
207-
* This action will stop marking notifications as read.
208-
*
209-
* @param {String} uid uid of the notification reader
210-
*/
211-
export const stopReadingNotifications = (uid) => (dispatch) => dispatch({
212-
type: STOP_READING_NOTIFICATIONS,
213-
payload: {
214-
uid,
215-
}
216-
})
166+
}

src/routes/notifications/reducers/index.js

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ import {
1616
TOGGLE_NOTIFICATIONS_DROPDOWN_MOBILE,
1717
TOGGLE_NOTIFICATIONS_DROPDOWN_WEB,
1818
MARK_NOTIFICATIONS_READ,
19-
START_READING_NOTIFICATIONS,
20-
STOP_READING_NOTIFICATIONS,
2119
} from '../../../config/constants'
2220
import _ from 'lodash'
2321

@@ -120,23 +118,6 @@ export default (state = initialState, action) => {
120118
return newState
121119
}
122120

123-
case START_READING_NOTIFICATIONS: {
124-
return {
125-
...state,
126-
readers: {
127-
...state.readers,
128-
[action.payload.uid]: action.payload.criteria
129-
}
130-
}
131-
}
132-
133-
case STOP_READING_NOTIFICATIONS: {
134-
return {
135-
...state,
136-
readers: _.omit(state.readers, action.payload.uid)
137-
}
138-
}
139-
140121
case VIEW_OLDER_NOTIFICATIONS_SUCCESS:
141122
return {...state,
142123
oldSourceIds: [...state.oldSourceIds, action.payload]

0 commit comments

Comments
 (0)