diff options
author | Brian Kim <brian@tagg.id> | 2021-06-01 14:43:30 -0700 |
---|---|---|
committer | Brian Kim <brian@tagg.id> | 2021-06-01 14:43:30 -0700 |
commit | 68fcf7c533ba7612c94760b1171c506f64bfc0ae (patch) | |
tree | b7afc5349b493cedf6f019ca9c6ab87dbb465597 /src/utils/common.ts | |
parent | 013dfb29a603fcd51105e0fa28e8b6adc0f49b86 (diff) |
Filled out basic front-end, need to integrate with back-end
Diffstat (limited to 'src/utils/common.ts')
-rw-r--r-- | src/utils/common.ts | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/utils/common.ts b/src/utils/common.ts index 95e77f64..9d0de64b 100644 --- a/src/utils/common.ts +++ b/src/utils/common.ts @@ -101,6 +101,27 @@ export const haveUnreadNotifications = async ( return false; }; +export const getUnreadNotifications = async ( + notifications: NotificationType[], +): Promise<NotificationType[]> => { + const outputNotifications = []; + for (const n of notifications) { + const notificationDate = moment(n.timestamp); + const prevLastViewed = await AsyncStorage.getItem('notificationLastViewed'); + const lastViewed: moment.Moment | undefined = + prevLastViewed == null ? moment.unix(0) : moment(prevLastViewed); + const dateAge = getDateAge(notificationDate); + if (dateAge === 'unknown') { + continue; + } + const unread = lastViewed ? lastViewed.diff(notificationDate) < 0 : false; + if (unread) { + outputNotifications.push(n); + } + } + return outputNotifications; +}; + // https://stackoverflow.com/a/2450976 export const shuffle = (array: any[]) => { var currentIndex = array.length, @@ -197,3 +218,7 @@ export const validateImageLink = async (url: string | undefined) => { return false; }); }; + +export const numberWithCommas = (digits: number) => { + return digits.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ','); +}; |