From 9ae27c5717bace27a2db2c8dab1241c8a6e3da25 Mon Sep 17 00:00:00 2001 From: ankit-thanekar007 Date: Wed, 5 May 2021 11:53:22 -0700 Subject: Added timestamps on notification --- src/utils/moments.ts | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src/utils') diff --git a/src/utils/moments.ts b/src/utils/moments.ts index 87f062af..12323e7b 100644 --- a/src/utils/moments.ts +++ b/src/utils/moments.ts @@ -37,3 +37,41 @@ export const getTimePosted = (date_time: string) => { } return time; }; + +export const getTimeInShorthand = (date_time: string) => { + //TODO: Explore this function to get dates in our range and format + // const datePosted = moment(date_time); + // return moment(datePosted).fromNow(); + + const datePosted = moment(date_time); + const now = moment(); + var time = date_time; + var difference = now.diff(datePosted, 's'); + + // Creating elapsedTime string to display to user + // 0 to less than 1 minute + if (difference < 60) { + time = difference + 's'; + } + // 1 minute to less than 1 hour + else if (difference >= 60 && difference < 60 * 60) { + difference = now.diff(datePosted, 'm'); + time = difference + 'm'; + } + // 1 hour to less than 1 day + else if (difference >= 60 * 60 && difference < 24 * 60 * 60) { + difference = now.diff(datePosted, 'h'); + time = difference + 'h'; + } + // Any number of days + else if (difference >= 24 * 60 * 60 && difference < 24 * 60 * 60 * 7) { + difference = now.diff(datePosted, 'd'); + time = difference + 'd'; + } + // More than 7 days + else if (difference >= 24 * 60 * 60 * 7) { + difference = now.diff(datePosted, 'w'); + time = difference + 'w'; + } + return time; +}; -- cgit v1.2.3-70-g09d2 From 679b46ac69149fb93a7a3781fa7f88c53dc77b33 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Fri, 7 May 2021 16:42:04 -0400 Subject: adjusted styling --- src/components/notifications/Notification.tsx | 21 ++++++++++++++------- src/utils/moments.ts | 4 ---- 2 files changed, 14 insertions(+), 11 deletions(-) (limited to 'src/utils') diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index 0290f9c7..ae884b42 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -253,10 +253,14 @@ const Notification: React.FC = (props) => { - {verbage} - - {getTimeInShorthand(timestamp)} + + {verbage} + + {' '} + {getTimeInShorthand(timestamp)} + + {/* {verbage} */} {/* Friend request accept/decline button */} @@ -317,6 +321,7 @@ const styles = StyleSheet.create({ contentContainer: { flex: 5, marginLeft: '5%', + marginRight: '3%', height: '80%', flexDirection: 'column', justifyContent: 'space-around', @@ -327,14 +332,16 @@ const styles = StyleSheet.create({ lineHeight: normalize(14.32), }, moment: { - height: 42, - width: 42, - right: '5%', + height: normalize(42), + width: normalize(42), }, buttonsContainer: { height: '80%', }, - textContainerStyles: {flexDirection: 'row', flexWrap: 'wrap'}, + textContainerStyles: { + flexDirection: 'row', + flexWrap: 'wrap', + }, verbageStyles: { fontWeight: '500', fontSize: normalize(11), diff --git a/src/utils/moments.ts b/src/utils/moments.ts index 12323e7b..90d69519 100644 --- a/src/utils/moments.ts +++ b/src/utils/moments.ts @@ -39,10 +39,6 @@ export const getTimePosted = (date_time: string) => { }; export const getTimeInShorthand = (date_time: string) => { - //TODO: Explore this function to get dates in our range and format - // const datePosted = moment(date_time); - // return moment(datePosted).fromNow(); - const datePosted = moment(date_time); const now = moment(); var time = date_time; -- cgit v1.2.3-70-g09d2