From df6595694c678657fec30d881fb1edcd39b62f17 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 15 Jan 2021 03:33:59 -0800 Subject: friend request --- src/components/notifications/Notification.tsx | 90 ++++++++++++++++++++------- 1 file changed, 66 insertions(+), 24 deletions(-) (limited to 'src/components/notifications') diff --git a/src/components/notifications/Notification.tsx b/src/components/notifications/Notification.tsx index f6a04526..5e68c6f3 100644 --- a/src/components/notifications/Notification.tsx +++ b/src/components/notifications/Notification.tsx @@ -1,17 +1,27 @@ import {useNavigation} from '@react-navigation/native'; import React, {useEffect, useState} from 'react'; import {Image, StyleSheet, Text, View} from 'react-native'; +import {Button} from 'react-native-elements'; import {TouchableWithoutFeedback} from 'react-native-gesture-handler'; import {useDispatch, useStore} from 'react-redux'; -import {loadAvatar} from '../../services'; +import { + declineFriendRequest, + loadUserNotifications, + updateUserXFriends, +} from '../../store/actions'; +import {TAGG_TEXT_LIGHT_BLUE} from '../../constants'; +import {loadAvatar, unfriendUser} from '../../services'; +import {acceptFriendRequest} from '../../store/actions'; import {RootState} from '../../store/rootReducer'; -import {NotificationType, ScreenType} from '../../types'; +import {NotificationType, ProfilePreviewType, ScreenType} from '../../types'; import { fetchUserX, + getTokenOrLogout, SCREEN_HEIGHT, SCREEN_WIDTH, userXInStore, } from '../../utils'; +import AcceptDeclineButtons from '../common/AcceptDeclineButtons'; interface NotificationProps { item: NotificationType; @@ -29,6 +39,7 @@ const Notification: React.FC = (props) => { }, screenType, } = props; + const navigation = useNavigation(); const state: RootState = useStore().getState(); const dispatch = useDispatch(); @@ -36,7 +47,6 @@ const Notification: React.FC = (props) => { 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) => { @@ -68,7 +78,8 @@ const Notification: React.FC = (props) => { const onNotificationTap = async () => { switch (notification_type) { - case 'FRD': + case 'FRD_ACPT': + case 'FRD_REQ': if (!userXInStore(state, screenType, id)) { await fetchUserX( dispatch, @@ -86,26 +97,45 @@ const Notification: React.FC = (props) => { } }; + // const handleAcceptRequest = async () => { + // const requester: ProfilePreviewType = { + // id: id, + // username: username, + // first_name: first_name, + // last_name: last_name, + // }; + // dispatch(acceptFriendRequest(requester)); + // dispatch(updateUserXFriends(id, state)); + // console.log('fetching notifications since user accepted request!'); + // dispatch(loadUserNotifications()); + // }; + + // const handleDeclineFriendRequest = async () => { + // dispatch(declineFriendRequest(id)); + // }; + return ( - - - - - - - {first_name} {last_name} - - {verbage} - + <> + + + + + + + {first_name} {last_name} + + {verbage} + + {/* TODO: Still WIP */} {/* {notification_type === 'CMT' && notification_object && ( = (props) => { source={{uri: momentURI, cache: 'only-if-cached'}} /> )} */} - + {notification_type === 'FRD_REQ' && ( + + + + )} + ); }; @@ -123,6 +160,8 @@ const styles = StyleSheet.create({ height: SCREEN_HEIGHT / 10, flex: 1, alignItems: 'center', + borderColor: 'red', + borderWidth: 2, }, avatarContainer: { marginLeft: '5%', @@ -152,6 +191,9 @@ const styles = StyleSheet.create({ width: 42, right: '5%', }, + buttonsContainer: { + + }, }); export default Notification; -- cgit v1.2.3-70-g09d2 From ed91266981e1662b512baa1856d8c921a8718e68 Mon Sep 17 00:00:00 2001 From: Ashm Walia Date: Fri, 15 Jan 2021 16:20:29 -0800 Subject: fixes --- src/components/common/AcceptDeclineButtons.tsx | 96 ++++++++++++++------------ src/components/notifications/Notification.tsx | 46 +++++------- src/components/profile/Content.tsx | 8 ++- src/components/profile/ProfileBody.tsx | 45 ++++++++++-- src/routes/Routes.tsx | 2 +- src/services/UserFriendsServices.ts | 2 +- src/store/actions/userFriends.ts | 1 - src/store/actions/userX.ts | 32 ++++++++- src/store/reducers/userXReducer.ts | 2 + src/utils/users.ts | 7 +- 10 files changed, 158 insertions(+), 83 deletions(-) (limited to 'src/components/notifications') diff --git a/src/components/common/AcceptDeclineButtons.tsx b/src/components/common/AcceptDeclineButtons.tsx index 2ebae029..164ce6e7 100644 --- a/src/components/common/AcceptDeclineButtons.tsx +++ b/src/components/common/AcceptDeclineButtons.tsx @@ -1,5 +1,12 @@ import React from 'react'; -import {StyleSheet, View} from 'react-native'; +import { + StyleProp, + StyleSheet, + Text, + View, + ViewProps, + ViewStyle, +} from 'react-native'; import {Button} from 'react-native-elements'; import {useDispatch, useStore} from 'react-redux'; import { @@ -12,73 +19,72 @@ import {acceptFriendRequest} from '../../store/actions'; import {RootState} from '../../store/rootReducer'; import {ProfilePreviewType} from '../../types'; import {SCREEN_WIDTH} from '../../utils'; +import {TouchableOpacity} from 'react-native-gesture-handler'; interface AcceptDeclineButtonsProps { requester: ProfilePreviewType; + onAccept: () => void; + onReject: () => void; + externalStyles?: Record>; } -const AcceptDeclineButtons: React.FC = (props) => { - const {requester} = props; - const state: RootState = useStore().getState(); - const dispatch = useDispatch(); - - const handleAcceptRequest = async () => { - dispatch(acceptFriendRequest(requester)); - dispatch(updateUserXFriends(requester.id, state)); - dispatch(loadUserNotifications()); - }; - - const handleDeclineFriendRequest = async () => { - dispatch(declineFriendRequest(requester.id)); - }; +const AcceptDeclineButtons: React.FC = ({ + requester, + onAccept, + onReject, + externalStyles, +}) => { return ( - <> -