diff options
author | ankit-thanekar007 <ankit.thanekar007@gmail.com> | 2021-02-15 15:05:36 -0800 |
---|---|---|
committer | ankit-thanekar007 <ankit.thanekar007@gmail.com> | 2021-02-15 15:05:36 -0800 |
commit | db2ebf4e73a491f2818f4d2575c10515d2a21614 (patch) | |
tree | aa1324d69e613b5e4ca303c972049b6609d3964a /src/screens/main/NotificationsScreen.tsx | |
parent | 2eaa9718131dcd9cb498f9b9e3c6b30dbbe3551c (diff) |
TMA-551: PR updates
Diffstat (limited to 'src/screens/main/NotificationsScreen.tsx')
-rw-r--r-- | src/screens/main/NotificationsScreen.tsx | 72 |
1 files changed, 37 insertions, 35 deletions
diff --git a/src/screens/main/NotificationsScreen.tsx b/src/screens/main/NotificationsScreen.tsx index 4979c8d8..d9e5a57f 100644 --- a/src/screens/main/NotificationsScreen.tsx +++ b/src/screens/main/NotificationsScreen.tsx @@ -97,42 +97,44 @@ const NotificationsScreen: React.FC = () => { // handles sectioning notifications to "date age" // mark notifications as read or unread useEffect(() => { - const sortedNotifications = (notifications ?? []) - .slice() - .sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1)); - let todays = []; - let yesterdays = []; - let thisWeeks = []; - for (const n of sortedNotifications) { - const notificationDate = moment(n.timestamp); - const dateAge = getDateAge(notificationDate); - if (dateAge === 'unknown') { - continue; - } - const unread = lastViewed ? lastViewed.diff(notificationDate) < 0 : false; - const newN = {...n, unread}; - switch (dateAge) { - case 'today': - todays.push(newN); - continue; - case 'yesterday': - yesterdays.push(newN); - continue; - case 'thisWeek': - thisWeeks.push(newN); - continue; - default: + if (notifications?.length > 0) { + const sortedNotifications = (notifications ?? []) + .slice() + .sort((a, b) => (a.timestamp < b.timestamp ? 1 : -1)); + let todays = []; + let yesterdays = []; + let thisWeeks = []; + for (const n of sortedNotifications) { + const notificationDate = moment(n.timestamp); + const dateAge = getDateAge(notificationDate); + if (dateAge === 'unknown') { continue; + } + const unread = lastViewed + ? lastViewed.diff(notificationDate) < 0 + : false; + const newN = {...n, unread}; + switch (dateAge) { + case 'today': + todays.push(newN); + continue; + case 'yesterday': + yesterdays.push(newN); + continue; + case 'thisWeek': + thisWeeks.push(newN); + continue; + default: + continue; + } } + setSectionedNotifications([ + {title: 'Today', data: todays}, + {title: 'Yesterday', data: yesterdays}, + {title: 'This Week', data: thisWeeks}, + ]); } - setSectionedNotifications([ - {title: 'Today', data: todays}, - {title: 'Yesterday', data: yesterdays}, - {title: 'This Week', data: thisWeeks}, - ]); - setNoNotification( - todays.length === 0 && yesterdays.length === 0 && thisWeeks.length === 0, - ); + setNoNotification(notifications && notifications.length === 0); }, [lastViewed, notifications]); const renderNotification = ({item}: {item: NotificationType}) => ( @@ -157,13 +159,13 @@ const NotificationsScreen: React.FC = () => { <Text style={styles.headerText}>Notifications</Text> <View style={styles.underline} /> </View> - {noNotification === true && ( + {noNotification && ( <View style={styles.emptyViewContainer}> <EmptyNotificationView /> </View> )} - {noNotification === false && ( + {!noNotification && ( <SectionList contentContainerStyle={styles.container} sections={sectionedNotifications} |