diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/components/profile/ProfileBody.tsx | 48 |
1 files changed, 25 insertions, 23 deletions
diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index 1a8d1e1a..dc68446b 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -1,5 +1,12 @@ import React, {useContext} from 'react'; -import {LayoutChangeEvent, Linking, StyleSheet, Text, View} from 'react-native'; +import { + Alert, + LayoutChangeEvent, + Linking, + StyleSheet, + Text, + View, +} from 'react-native'; import {normalize} from 'react-native-elements'; import {useDispatch, useSelector, useStore} from 'react-redux'; import {TAGG_DARK_BLUE, TOGGLE_BUTTON_TYPE} from '../../constants'; @@ -20,9 +27,8 @@ import { } from '../../utils'; import {FriendsButton, BasicButton} from '../common'; import ToggleButton from './ToggleButton'; -// import {ChatContext} from '../../App'; -// import {useNavigation} from '@react-navigation/core'; -// import AsyncStorage from '@react-native-community/async-storage'; +import {ChatContext} from '../../App'; +import {useNavigation} from '@react-navigation/core'; interface ProfileBodyProps { onLayout: (event: LayoutChangeEvent) => void; @@ -38,6 +44,9 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ userXId, screenType, }) => { + const dispatch = useDispatch(); + const navigation = useNavigation(); + const {profile = NO_PROFILE, user} = useSelector((state: RootState) => userXId ? state.userX[screenType][userXId] : state.user, ); @@ -54,10 +63,10 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ profile, ); + const {chatClientReady} = useSelector((state: RootState) => state.user); + const {chatClient, setChannel} = useContext(ChatContext); + const state: RootState = useStore().getState(); - const dispatch = useDispatch(); - // const navigation = useNavigation(); - // const {chatClient, setChannel} = useContext(ChatContext); const loggedInUserId = state.user.user.userId; const handleAcceptRequest = async () => { @@ -88,22 +97,15 @@ const ProfileBody: React.FC<ProfileBodyProps> = ({ }; const onPressMessage = async () => { - // TODO: Use function from util to create the channel and then navigate to screen - // const channelName = username + ' and ' + state.user.user.username; - // const chatToken = await AsyncStorage.getItem('chatToken'); - // await chatClient.connectUser( - // { - // id: loggedInUserId, - // }, - // chatToken, - // ); - // const channel = chatClient.channel('messaging', { - // name: channelName, - // members: [loggedInUserId, String(userXId)], - // }); - // channel.create(); - // navigation.navigate('Chat'); - console.log('Navigate to ChatScreen'); + if (!chatClientReady) { + Alert.alert('Something wrong with chat'); + } + const channel = chatClient.channel('messaging', { + members: [loggedInUserId, String(userXId)], + }); + channel.create(); + setChannel(channel); + navigation.navigate('Chat'); }; return ( |