From bd2f89805d0bb1c2f1d08fe8d91099aa4f109d35 Mon Sep 17 00:00:00 2001 From: Ivan Chen Date: Tue, 29 Dec 2020 20:21:24 -0500 Subject: [TMA-461] Notifications Screen (#151) * renamed ProfileStack to MainStack, created initial notifications data type * cleaned up code * added notifications to redux * finished sectioned list * updated types to make more sense * finished sectioned notifications by date * updated notification type and tested mock backend integration * finished read or unread logic * minor changes * another minor fix * finished integration * moved stuff * added ability to navigate to user profile Co-authored-by: Husam Salhab <47015061+hsalhab@users.noreply.github.com> --- src/components/notifications/Notification.tsx | 150 ++++++++++++++++++++++++++ src/components/notifications/index.ts | 1 + 2 files changed, 151 insertions(+) create mode 100644 src/components/notifications/Notification.tsx create mode 100644 src/components/notifications/index.ts (limited to 'src/components/notifications') diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx new file mode 100644 index 00000000..f533e42d --- /dev/null +++ b/src/components/notifications/Notification.tsx @@ -0,0 +1,150 @@ +import {useNavigation} from '@react-navigation/native'; +import React, {useEffect, useState} from 'react'; +import {Image, StyleSheet, Text, View} from 'react-native'; +import {TouchableWithoutFeedback} from 'react-native-gesture-handler'; +import {useDispatch, useStore} from 'react-redux'; +import {loadAvatar} from '../../services'; +import {RootState} from '../../store/rootReducer'; +import {NotificationType, ScreenType} from '../../types'; +import {fetchUserX, SCREEN_HEIGHT, userXInStore} from '../../utils'; + +interface NotificationProps { + item: NotificationType; + screenType: ScreenType; +} + +const Notification: React.FC = (props) => { + const { + item: { + actor: {id, username, first_name, last_name}, + verbage, + notification_type, + notification_object, + unread, + }, + screenType, + } = props; + const navigation = useNavigation(); + const state: RootState = useStore().getState(); + const dispatch = useDispatch(); + + const [avatarURI, setAvatarURI] = useState(undefined); + const [momentURI, setMomentURI] = useState(undefined); + const backgroundColor = unread ? '#DCF1F1' : 'rgba(0,0,0,0)'; + + useEffect(() => { + let mounted = true; + const loadAvatarImage = async (user_id: string) => { + const response = await loadAvatar(user_id, true); + if (mounted) { + setAvatarURI(response); + } + }; + loadAvatarImage(id); + return () => { + mounted = false; + }; + }, [id]); + + // TODO: this should be moment thumbnail, waiting for that to complete + // useEffect(() => { + // let mounted = true; + // const loadMomentImage = async (user_id: string) => { + // const response = await loadAvatar(user_id, true); + // if (mounted) { + // setMomentURI(response); + // } + // }; + // loadMomentImage(id); + // return () => { + // mounted = false; + // }; + // }, [id, notification_object]); + + const onNotificationTap = async () => { + switch (notification_type) { + case 'FLO': + if (!userXInStore(state, screenType, id)) { + await fetchUserX( + dispatch, + {userId: id, username: username}, + screenType, + ); + } + navigation.push('Profile', { + userXId: id, + screenType, + }); + break; + default: + break; + } + }; + + return ( + + + + + + + {first_name} {last_name} + + {verbage} + + {/* TODO: Still WIP */} + {/* {notification_type === 'CMT' && notification_object && ( + + )} */} + + ); +}; + +const styles = StyleSheet.create({ + container: { + flexDirection: 'row', + height: SCREEN_HEIGHT / 12, + flex: 1, + alignItems: 'center', + }, + avatarContainer: { + marginLeft: '5%', + flex: 1, + justifyContent: 'center', + }, + avatar: { + height: 42, + width: 42, + borderRadius: 20, + }, + contentContainer: { + flex: 5, + marginLeft: '5%', + height: '80%', + flexDirection: 'column', + justifyContent: 'space-around', + }, + actorName: { + fontWeight: 'bold', + }, + moment: { + position: 'absolute', + height: 42, + width: 42, + right: '5%', + }, +}); + +export default Notification; diff --git a/src/components/notifications/index.ts b/src/components/notifications/index.ts new file mode 100644 index 00000000..0260ce24 --- /dev/null +++ b/src/components/notifications/index.ts @@ -0,0 +1 @@ +export {default as Notification} from './Notification'; -- cgit v1.2.3-70-g09d2