From db2ebf4e73a491f2818f4d2575c10515d2a21614 Mon Sep 17 00:00:00 2001 From: ankit-thanekar007 Date: Mon, 15 Feb 2021 15:05:36 -0800 Subject: TMA-551: PR updates --- src/screens/main/NotificationsScreen.tsx | 72 +++++++++++----------- .../main/notification/EmptyNotificationView.tsx | 13 ++-- 2 files changed, 43 insertions(+), 42 deletions(-) (limited to 'src/screens/main') 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 = () => { Notifications - {noNotification === true && ( + {noNotification && ( )} - {noNotification === false && ( + {!noNotification && ( { return ( @@ -27,19 +28,17 @@ const EmptyNotificationView: React.FC = () => { const styles = StyleSheet.create({ container: {alignItems: 'center'}, - topMargin: {marginTop: 43}, + topMargin: {marginTop: SCREEN_HEIGHT * 0.025}, upperTextStyle: { fontWeight: '700', - fontSize: 23, - fontStyle: 'normal', - lineHeight: 40, + fontSize: normalize(23), + lineHeight: normalize(40), }, bottomTextStyle: { color: '#2D3B45', fontWeight: '600', - fontSize: 20, - fontStyle: 'normal', - lineHeight: 40, + fontSize: normalize(20), + lineHeight: normalize(40), }, backgroundLinearView: { borderRadius: 135.5, -- cgit v1.2.3-70-g09d2