diff options
author | Ivan Chen <ivan@tagg.id> | 2021-05-07 16:55:14 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-07 16:55:14 -0400 |
commit | 893e7bf7a49eb612a975dddae4d792a035b9f420 (patch) | |
tree | 25d8200a7479ca14cc1984ebd45c151344d157f3 /src | |
parent | 85dbf012ad864a1149939c7eaf43c3ebb56a1853 (diff) | |
parent | 679b46ac69149fb93a7a3781fa7f88c53dc77b33 (diff) |
Merge pull request #402 from ankit-thanekar007/tma-800-notification-timestamp
[TMA-800] : Added timestamps on notification
Diffstat (limited to 'src')
-rw-r--r-- | src/components/notifications/Notification.tsx | 49 | ||||
-rw-r--r-- | src/utils/moments.ts | 34 |
2 files changed, 76 insertions, 7 deletions
diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index a74480b4..ae884b42 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -26,6 +26,8 @@ import { } from '../../types'; import { fetchUserX, + getTimeInShorthand, + normalize, SCREEN_HEIGHT, SCREEN_WIDTH, userXInStore, @@ -47,6 +49,7 @@ const Notification: React.FC<NotificationProps> = (props) => { notification_type, notification_object, unread, + timestamp, }, screenType, loggedInUser, @@ -231,7 +234,12 @@ const Notification: React.FC<NotificationProps> = (props) => { {notification_type === 'SYSTEM_MSG' ? ( // Only verbage <View style={styles.contentContainer}> - <Text style={styles.actorName}>{verbage}</Text> + <View style={styles.textContainerStyles}> + <Text style={styles.actorName}>{verbage}</Text> + <Text style={styles.timeStampStyles}> + {getTimeInShorthand(timestamp)} + </Text> + </View> </View> ) : ( <> @@ -242,8 +250,17 @@ const Notification: React.FC<NotificationProps> = (props) => { {first_name} {last_name} </Text> </TouchableWithoutFeedback> - <TouchableWithoutFeedback onPress={onNotificationTap}> - <Text>{verbage}</Text> + <TouchableWithoutFeedback + style={styles.textContainerStyles} + onPress={onNotificationTap}> + <Text style={styles.verbageStyles}> + {verbage} + <Text style={styles.timeStampStyles}> + {' '} + {getTimeInShorthand(timestamp)} + </Text> + </Text> + {/* <Text style={styles.verbageStyles}>{verbage}</Text> */} </TouchableWithoutFeedback> </View> {/* Friend request accept/decline button */} @@ -304,22 +321,40 @@ const styles = StyleSheet.create({ contentContainer: { flex: 5, marginLeft: '5%', + marginRight: '3%', height: '80%', flexDirection: 'column', justifyContent: 'space-around', }, actorName: { - fontSize: 15, + fontSize: normalize(12), fontWeight: '700', + 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', + }, + verbageStyles: { + fontWeight: '500', + fontSize: normalize(11), + lineHeight: normalize(13.13), + }, + timeStampStyles: { + fontWeight: '700', + fontSize: normalize(12), + lineHeight: normalize(14.32), + marginHorizontal: 2, + color: '#828282', + textAlignVertical: 'center', + }, imageFlex: { flex: 1, }, diff --git a/src/utils/moments.ts b/src/utils/moments.ts index 87f062af..90d69519 100644 --- a/src/utils/moments.ts +++ b/src/utils/moments.ts @@ -37,3 +37,37 @@ export const getTimePosted = (date_time: string) => { } return time; }; + +export const getTimeInShorthand = (date_time: string) => { + 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; +}; |