From bdd1ed17600da7b766e2b0fa97ad4cbf01234819 Mon Sep 17 00:00:00 2001 From: Shravya Ramesh Date: Fri, 9 Apr 2021 13:46:42 -0700 Subject: removed client ready from redux --- src/components/profile/ProfileBody.tsx | 6 ++-- src/routes/Routes.tsx | 2 +- src/screens/chat/ChatListScreen.tsx | 51 +++++++++++++++------------------- src/store/actions/user.ts | 15 ---------- src/store/initialStates.ts | 1 - src/utils/messages.ts | 4 +-- 6 files changed, 28 insertions(+), 51 deletions(-) (limited to 'src') diff --git a/src/components/profile/ProfileBody.tsx b/src/components/profile/ProfileBody.tsx index dc68446b..e23249fa 100644 --- a/src/components/profile/ProfileBody.tsx +++ b/src/components/profile/ProfileBody.tsx @@ -63,7 +63,6 @@ const ProfileBody: React.FC = ({ profile, ); - const {chatClientReady} = useSelector((state: RootState) => state.user); const {chatClient, setChannel} = useContext(ChatContext); const state: RootState = useStore().getState(); @@ -97,8 +96,9 @@ const ProfileBody: React.FC = ({ }; const onPressMessage = async () => { - if (!chatClientReady) { - Alert.alert('Something wrong with chat'); + if (!chatClient.user) { + // TODO: Add refresh control to retry establishing chat connection + Alert.alert('Unable to connect chat'); } const channel = chatClient.channel('messaging', { members: [loggedInUserId, String(userXId)], diff --git a/src/routes/Routes.tsx b/src/routes/Routes.tsx index 173a6a6c..adc6253b 100644 --- a/src/routes/Routes.tsx +++ b/src/routes/Routes.tsx @@ -54,7 +54,7 @@ const Routes: React.FC = () => { if (userId) { fcmService.setUpPushNotifications(); fcmService.sendFcmTokenToServer(); - connectChatAccount(loggedInUserId, chatClient, dispatch); + connectChatAccount(loggedInUserId, chatClient); } }, []); diff --git a/src/screens/chat/ChatListScreen.tsx b/src/screens/chat/ChatListScreen.tsx index dbdb7994..eb886232 100644 --- a/src/screens/chat/ChatListScreen.tsx +++ b/src/screens/chat/ChatListScreen.tsx @@ -31,9 +31,6 @@ interface ChatListScreenProps { */ const ChatListScreen: React.FC = () => { const {chatClient} = useContext(ChatContext); - const chatClientReady = useSelector( - (state: RootState) => state.user.chatClientReady, - ); const state: RootState = useStore().getState(); const loggedInUserId = state.user.user.userId; @@ -65,31 +62,29 @@ const ChatListScreen: React.FC = () => { channel.create(); }} /> - {chatClientReady && ( - - - - filters={memoizedFilters} - options={{ - presence: true, - state: true, - watch: true, - }} - sort={{last_message_at: -1}} - maxUnreadCount={99} - Preview={ChannelPreview} - /> - - - )} + + + + filters={memoizedFilters} + options={{ + presence: true, + state: true, + watch: true, + }} + sort={{last_message_at: -1}} + maxUnreadCount={99} + Preview={ChannelPreview} + /> + + diff --git a/src/store/actions/user.ts b/src/store/actions/user.ts index 0ed57fe6..c7d0d5a7 100644 --- a/src/store/actions/user.ts +++ b/src/store/actions/user.ts @@ -11,7 +11,6 @@ import {getTokenOrLogout} from '../../utils'; import { clearHeaderAndProfileImages, profileCompletionStageUpdated, - setChatClientReady, setIsOnboardedUser, setNewNotificationReceived, setNewVersionAvailable, @@ -235,17 +234,3 @@ export const suggestedPeopleAnimatedTutorialFinished = ( } }; -export const updateChatClientReady = ( - chatClientReady: boolean, -): ThunkAction, RootState, unknown, Action> => async ( - dispatch, -) => { - try { - dispatch({ - type: setChatClientReady.type, - payload: {chatClientReady}, - }); - } catch (error) { - console.log(error); - } -}; diff --git a/src/store/initialStates.ts b/src/store/initialStates.ts index 546c57a9..02331eb6 100644 --- a/src/store/initialStates.ts +++ b/src/store/initialStates.ts @@ -41,7 +41,6 @@ export const EMPTY_PROFILE_PREVIEW_LIST = []; export const NO_USER_DATA = { user: NO_USER, - chatClientReady: false, profile: NO_PROFILE, avatar: undefined, cover: undefined, diff --git a/src/utils/messages.ts b/src/utils/messages.ts index b2162d34..1c83ca9f 100644 --- a/src/utils/messages.ts +++ b/src/utils/messages.ts @@ -1,6 +1,6 @@ import AsyncStorage from '@react-native-community/async-storage'; import moment from 'moment'; -import {updateChatClientReady} from '../store/actions'; +// import {updateChatClientReady} from '../store/actions'; import {AppDispatch} from '../store/configureStore'; import {RootState} from '../store/rootReducer'; import {ChannelGroupedType} from '../types'; @@ -98,9 +98,7 @@ export const connectChatAccount = async ( }, chatToken, ); - dispatch(updateChatClientReady(true)); } catch (err) { - dispatch(updateChatClientReady(false)); console.log('Error while connecting user to Stream: ', err); } }; -- cgit v1.2.3-70-g09d2