aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorankit-thanekar007 <ankit.thanekar007@gmail.com>2021-02-15 16:30:16 -0800
committerankit-thanekar007 <ankit.thanekar007@gmail.com>2021-02-15 16:30:16 -0800
commita9b60f95f8f863249c79de8e4ae07301f75005de (patch)
tree11994e325711dff67cd8aa2012a890a9579e2c5b /src
parentdb2ebf4e73a491f2818f4d2575c10515d2a21614 (diff)
TMA-551: PR updates
Diffstat (limited to 'src')
-rw-r--r--src/screens/main/NotificationsScreen.tsx68
1 files changed, 33 insertions, 35 deletions
diff --git a/src/screens/main/NotificationsScreen.tsx b/src/screens/main/NotificationsScreen.tsx
index d9e5a57f..ca921f75 100644
--- a/src/screens/main/NotificationsScreen.tsx
+++ b/src/screens/main/NotificationsScreen.tsx
@@ -97,44 +97,42 @@ const NotificationsScreen: React.FC = () => {
// handles sectioning notifications to "date age"
// mark notifications as read or unread
useEffect(() => {
- 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') {
+ 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;
- }
- 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},
- ]);
}
- setNoNotification(notifications && notifications.length === 0);
+ setSectionedNotifications([
+ {title: 'Today', data: todays},
+ {title: 'Yesterday', data: yesterdays},
+ {title: 'This Week', data: thisWeeks},
+ ]);
+ setNoNotification(
+ todays.length === 0 && yesterdays.length === 0 && thisWeeks.length === 0,
+ );
}, [lastViewed, notifications]);
const renderNotification = ({item}: {item: NotificationType}) => (