@@ -8,11 +8,12 @@ import { Link } from 'react-router-dom'
88import { connect } from 'react-redux'
99import _ from 'lodash'
1010import { TransitionGroup , Transition } from 'react-transition-group'
11- import { getNotifications , toggleNotificationSeen , markAllNotificationsRead , toggleNotificationRead , visitNotifications ,
11+ import { getNotifications , toggleNotificationSeen , markAllNotificationsRead , markAllNotificationsSeen , toggleNotificationRead ,
1212 toggleBundledNotificationRead , viewOlderNotifications , hideOlderNotifications } from '../../routes/notifications/actions'
1313import {
1414 splitNotificationsBySources ,
1515 filterReadNotifications ,
16+ filterSeenNotifications ,
1617 limitQuantityInSources ,
1718 preRenderNotifications ,
1819} from '../../routes/notifications/helpers/notifications'
@@ -29,9 +30,9 @@ import { NOTIFICATIONS_DROPDOWN_PER_SOURCE, NOTIFICATIONS_NEW_PER_SOURCE, REFRES
2930import './NotificationsDropdown.scss'
3031
3132const NotificationsDropdownContainerView = ( props ) => {
32- const { initialized, isLoading, lastVisited , sources, notifications, markAllNotificationsRead, toggleNotificationRead, toggleNotificationSeen,
33- pending, toggleBundledNotificationRead, visitNotifications , oldSourceIds, viewOlderNotifications, isDropdownMobileOpen, isDropdownWebOpen,
34- toggleNotificationsDropdownMobile, toggleNotificationsDropdownWeb } = props
33+ const { initialized, isLoading, sources, notifications, markAllNotificationsRead, toggleNotificationRead, toggleNotificationSeen,
34+ pending, toggleBundledNotificationRead, oldSourceIds, viewOlderNotifications, isDropdownMobileOpen, isDropdownWebOpen,
35+ toggleNotificationsDropdownMobile, toggleNotificationsDropdownWeb, markAllNotificationsSeen } = props
3536 if ( ! initialized && isLoading ) {
3637 return (
3738 < NotificationsDropdown hasUnread = { false } >
@@ -51,9 +52,11 @@ const NotificationsDropdownContainerView = (props) => {
5152 }
5253
5354 const notReadNotifications = filterReadNotifications ( notifications )
55+ const notSeenNotifications = filterSeenNotifications ( notifications )
5456 const allNotificationsBySources = splitNotificationsBySources ( sources , notReadNotifications )
5557
5658 const hasUnread = notReadNotifications . length > 0
59+ const hasUnseen = notSeenNotifications . length > 0
5760 // we have to give Dropdown component some time
5861 // before removing notification item node from the list
5962 // otherwise dropdown thinks we clicked outside and closes dropdown
@@ -70,7 +73,7 @@ const NotificationsDropdownContainerView = (props) => {
7073 } , 0 )
7174 }
7275 }
73- const hasNew = hasUnread && lastVisited < _ . maxBy ( _ . map ( notifications , n => new Date ( n . date ) ) )
76+
7477 let notificationsEmpty = (
7578 < NotificationsEmpty >
7679 < p className = "notifications-empty-note" >
@@ -92,6 +95,12 @@ const NotificationsDropdownContainerView = (props) => {
9295 )
9396 }
9497
98+ const markNotificationsSeen = ( isOpen ) => {
99+ if ( isOpen ) {
100+ markAllNotificationsSeen ( null , notifications )
101+ }
102+ }
103+
95104 // this function checks that notification is not seen yet,
96105 // before marking it as seen
97106 const markNotificationSeen = ( notificationId ) => {
@@ -118,10 +127,10 @@ const NotificationsDropdownContainerView = (props) => {
118127 return (
119128 < NotificationsDropdown
120129 hasUnread = { hasUnread }
121- hasNew = { hasNew }
130+ hasNew = { hasUnseen }
122131 onToggle = { ( isOpen ) => {
123132 toggleNotificationsDropdownWeb ( isOpen )
124- visitNotifications ( )
133+ markNotificationsSeen ( isOpen )
125134 } }
126135 >
127136 { isDropdownWebOpen && < div >
@@ -192,10 +201,9 @@ const NotificationsDropdownContainerView = (props) => {
192201 return (
193202 < NotificationsMobilePage
194203 hasUnread = { hasUnread }
195- hasNew = { hasNew }
204+ hasNew = { hasUnseen }
196205 onToggle = { ( ) => {
197206 toggleNotificationsDropdownMobile ( )
198- visitNotifications ( )
199207 } }
200208 isOpen = { isDropdownMobileOpen }
201209 >
@@ -253,21 +261,18 @@ class NotificationsDropdownContainer extends React.Component {
253261 constructor ( props ) {
254262 super ( props )
255263 this . state = {
256- lastVisited : new Date ( 0 ) ,
257264 isDropdownWebOpen : false ,
258265 isDropdownMobileOpen : false ,
259266 notificationsVisited : false ,
260267 }
261268
262269 this . onToggleNotificationsDropdownWeb = this . onToggleNotificationsDropdownWeb . bind ( this )
263270 this . onToggleNotificationsDropdownMobile = this . onToggleNotificationsDropdownMobile . bind ( this )
264- this . onVisitNotifications = this . onVisitNotifications . bind ( this )
265271 }
266272
267273 componentDidMount ( ) {
268274 this . props . getNotifications ( )
269275 this . autoRefreshNotifications = setInterval ( ( ) => this . props . getNotifications ( ) , REFRESH_NOTIFICATIONS_INTERVAL )
270- this . setState ( { lastVisited : this . props . lastVisited } )
271276 }
272277
273278 componentWillUnmount ( ) {
@@ -276,7 +281,6 @@ class NotificationsDropdownContainer extends React.Component {
276281 this . onToggleNotificationsDropdownMobile ( false )
277282 this . onToggleNotificationsDropdownWeb ( false )
278283 this . props . hideOlderNotifications ( )
279- this . state . notificationsVisited && this . props . visitNotifications ( )
280284 }
281285
282286 componentWillReceiveProps ( nextProps ) {
@@ -300,25 +304,15 @@ class NotificationsDropdownContainer extends React.Component {
300304 this . setState ( { isDropdownMobileOpen : ! _ . isUndefined ( isOpen ) ? isOpen : ! this . state . isDropdownMobileOpen } )
301305 }
302306
303- onVisitNotifications ( ) {
304- this . setState ( {
305- lastVisited : _ . maxBy ( _ . map ( this . props . notifications , n => new Date ( n . date ) ) ) ,
306- notificationsVisited : true
307- } )
308- }
309-
310307 render ( ) {
311308 const { notifications, ...restProps } = this . props
312309 const preRenderedNotifications = preRenderNotifications ( notifications )
313-
314310 return (
315311 < NotificationsDropdownContainerView
316312 { ...restProps }
317313 notifications = { preRenderedNotifications }
318314 toggleNotificationsDropdownWeb = { this . onToggleNotificationsDropdownWeb }
319315 toggleNotificationsDropdownMobile = { this . onToggleNotificationsDropdownMobile }
320- visitNotifications = { this . onVisitNotifications }
321- lastVisited = { this . state . lastVisited }
322316 isDropdownMobileOpen = { this . state . isDropdownMobileOpen }
323317 isDropdownWebOpen = { this . state . isDropdownWebOpen }
324318 />
@@ -331,9 +325,9 @@ const mapStateToProps = ({ notifications }) => notifications
331325
332326const mapDispatchToProps = {
333327 getNotifications,
334- visitNotifications,
335328 toggleNotificationSeen,
336329 markAllNotificationsRead,
330+ markAllNotificationsSeen,
337331 toggleNotificationRead,
338332 toggleBundledNotificationRead,
339333 viewOlderNotifications,
0 commit comments