aboutsummaryrefslogtreecommitdiff
path: root/src/components/profile/ProfileBody.tsx
diff options
context:
space:
mode:
authorShravya Ramesh <shravs1208@gmail.com>2021-04-09 11:31:34 -0700
committerShravya Ramesh <shravs1208@gmail.com>2021-04-09 11:31:34 -0700
commitd601b6dcf93dc1e326a9e79c5b19db6bcdaedbdf (patch)
tree7702ce57960963826bc517df15776c36eb20e359 /src/components/profile/ProfileBody.tsx
parentbc56de68eb8fc69be6c5c105236d0b6ecfac4b26 (diff)
Navigating to chat from profile body msg btn
Diffstat (limited to 'src/components/profile/ProfileBody.tsx')
-rw-r--r--src/components/profile/ProfileBody.tsx48
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 (