diff options
author | Ivan Chen <ivan@tagg.id> | 2021-06-09 17:37:40 -0400 |
---|---|---|
committer | Ivan Chen <ivan@tagg.id> | 2021-06-09 17:37:40 -0400 |
commit | 93796732be3f5070c0a124d29533396f79736c83 (patch) | |
tree | 775b70c4b5b5dabba21009de3459091a5e94d6af /src | |
parent | 3f42ed623adf591543bb8b738077e9172781ed09 (diff) |
Cleanup code
Diffstat (limited to 'src')
-rw-r--r-- | src/components/notifications/NotificationPill.tsx | 15 | ||||
-rw-r--r-- | src/services/NotificationService.ts | 10 | ||||
-rw-r--r-- | src/types/types.ts | 4 |
3 files changed, 16 insertions, 13 deletions
diff --git a/src/components/notifications/NotificationPill.tsx b/src/components/notifications/NotificationPill.tsx index 7017d2e7..01622a6f 100644 --- a/src/components/notifications/NotificationPill.tsx +++ b/src/components/notifications/NotificationPill.tsx @@ -20,7 +20,12 @@ export const NotificationPill: React.FC<NotificationPillProps> = ({ }) => { const [iconStart, setIconStart] = useState<number[]>([0, -100]); const [tipStart, setTipStart] = useState<number[]>([0, -100]); - const [notificationSets, setNotificationSets] = useState({}); + const [notificationSets, setNotificationSets] = useState<{ + CMT?: number; + FRD_REQ?: number; + P_VIEW?: number; + MOM_TAG?: number; + }>({}); const [timeCount, setTimeCount] = useState<boolean>(false); const [timeOut, setTimeOut] = useState<boolean>(false); const iconRef = useRef(null); @@ -84,7 +89,9 @@ export const NotificationPill: React.FC<NotificationPillProps> = ({ const getCount = async () => { const data = await getNotificationsUnreadCount(); setTimeout(() => { - setNotificationSets(data); + if (data) { + setNotificationSets(data); + } }, 100); }; @@ -117,14 +124,14 @@ export const NotificationPill: React.FC<NotificationPillProps> = ({ </Text> </> )} - {notificationSets.FR_REQ && ( + {notificationSets.FRD_REQ && ( <> <Image source={require('../../assets/images/pill-icon-2.png')} style={styles.indicationIcon} /> <Text style={styles.text}> - {numberWithCommas(notificationSets.FR_REQ)} + {numberWithCommas(notificationSets.FRD_REQ)} </Text> </> )} diff --git a/src/services/NotificationService.ts b/src/services/NotificationService.ts index 2ffc85b2..ccaa9135 100644 --- a/src/services/NotificationService.ts +++ b/src/services/NotificationService.ts @@ -34,12 +34,7 @@ export const getNotificationsData: () => Promise<NotificationType[]> = } }; -export const getNotificationsUnreadCount: () => Promise<{ - CMT?: number; - FRD_REQ?: number; - P_VIEW?: number; - MOM_TAG?: number; -}> = async () => { +export const getNotificationsUnreadCount = async () => { try { const token = await AsyncStorage.getItem('token'); const response = await fetch(NOTIFICATIONS_COUNT_ENDPOINT, { @@ -70,11 +65,10 @@ export const getNotificationsUnreadCount: () => Promise<{ } return typedData; } - return []; } catch (error) { console.log('Unable to fetch notifications'); - return []; } + return undefined; }; export const setNotificationsReadDate: () => Promise<boolean> = async () => { diff --git a/src/types/types.ts b/src/types/types.ts index e54c2201..fd75ab50 100644 --- a/src/types/types.ts +++ b/src/types/types.ts @@ -254,7 +254,9 @@ export type TypeOfNotification = // notification_object is MomentType | 'MOM_TAG' // notification_object is undefined - | 'SYSTEM_MSG'; + | 'SYSTEM_MSG' + // notification_object is undefined + | 'P_VIEW'; export type UniversityBadge = { id: number; |