Skip to content

Commit

Permalink
Merge branch 'development' into fix/bt-791-render-waiting-approval-label
Browse files Browse the repository at this point in the history
  • Loading branch information
nika-sirak committed Sep 28, 2023
2 parents 58fc1b2 + 65e5516 commit faaeac0
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 27 deletions.
16 changes: 10 additions & 6 deletions mobile/src/bundles/chat/screens/chat-list/chat-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
View,
} from '~/bundles/common/components/components';
import {
DataStatus,
RootScreenName,
TextCategory,
UserRole,
Expand All @@ -38,17 +37,22 @@ import { styles } from './styles';
const ChatList: React.FC = () => {
const dispatch = useAppDispatch();
const { currentUserData: user } = useAppSelector(({ auth }) => auth);
const { chats, current, dataStatus } = useAppSelector(({ chat }) => chat);

const isChatsLoading = dataStatus === DataStatus.PENDING;
const { chats, current } = useAppSelector(({ chat }) => chat);
const [isDataLoaded, setDataLoaded] = useState(false);
const [searchQuery, setSearchQuery] = useState('');

const navigation =
useNavigation<NavigationProp<RootNavigationParameterList>>();

useEffect(() => {
if (user) {
void dispatch(chatActions.getAllChatsByUserId(user.id));
void dispatch(chatActions.getAllChatsByUserId(user.id)).then(() => {
setDataLoaded(true);
});

return () => {
setDataLoaded(false);
};
}
}, [dispatch, user, current.messages.length]);

Expand Down Expand Up @@ -92,7 +96,7 @@ const ChatList: React.FC = () => {
[navigation],
);

if (isChatsLoading) {
if (!isDataLoaded) {
return <Loader />;
}

Expand Down
20 changes: 16 additions & 4 deletions mobile/src/bundles/chat/screens/chat/chat.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useState } from 'react';

import {
ChatHeader,
Expand All @@ -7,7 +7,7 @@ import {
} from '~/bundles/chat/components/components';
import { actions as chatActions } from '~/bundles/chat/store';
import { type ChatMessagesCreateRequestDto } from '~/bundles/chat/types/types';
import { FlatList, View } from '~/bundles/common/components/components';
import { FlatList, Loader, View } from '~/bundles/common/components/components';
import {
useAppDispatch,
useAppRoute,
Expand All @@ -23,17 +23,25 @@ import { styles } from './styles';
const Chat: React.FC = () => {
const route = useAppRoute();
const dispatch = useAppDispatch();
const { current } = useAppSelector(({ chat }) => chat);
const [isDataLoaded, setDataLoaded] = useState(false);

const { chatId, partnerName, partnerAvatar, partnerId } =
route.params as ChatNavigationProperties;
const { current } = useAppSelector(({ chat }) => chat);

useEffect(() => {
void dispatch(
chatActions.getAllMessagesByChatId({
chatId,
employerId: partnerId,
}),
);
).then(() => {
setDataLoaded(true);
});

return () => {
setDataLoaded(false);
};
}, [dispatch, chatId, partnerId]);

const handleSendMessage = useCallback(
Expand All @@ -58,6 +66,10 @@ const Chat: React.FC = () => {
);
};

if (!isDataLoaded) {
return <Loader />;
}

return (
<View style={[globalStyles.flex1, styles.chatContainer]}>
<ChatHeader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,28 @@ const ContactCandidate: React.FC = () => {
const route = useAppRoute();
const { currentUserData } = useAppSelector(({ auth }) => auth);
const { chats, dataStatus } = useAppSelector(({ chat }) => chat);
const { talentId, profileName } =
route.params as ContactTalentNavigationPropertiesType;
const isLoading = dataStatus === DataStatus.PENDING;

const navigation =
useNavigation<NavigationProp<RootNavigationParameterList>>();

const dispatch = useAppDispatch();

const startedChat = chats.find((chat) => chat.chatId === talentId);
const { talentId } = route.params as ContactTalentNavigationPropertiesType;

const startedChat = chats.find(({ participants }) => {
const { sender, receiver } = participants;
return (
(sender.id === currentUserData?.id && receiver.id === talentId) ||
(receiver.id === currentUserData?.id && sender.id === talentId)
);
});

useEffect(() => {
if (currentUserData?.id) {
void dispatch(getAllChatsByUserId(currentUserData.id));
}
}, [currentUserData, dispatch]);
}, [currentUserData?.id, dispatch, talentId]);

useEffect(() => {
if (startedChat) {
Expand All @@ -61,38 +69,27 @@ const ContactCandidate: React.FC = () => {
}),
);
}
}, [navigation, startedChat]);
}, [navigation, chats, startedChat]);

const handleFormSubmit = useCallback(
(payload: ContactCandidateDto): void => {
if (currentUserData?.id && talentId) {
void dispatch(
chatActions.createMessage({
chatId: talentId,
senderId: currentUserData.id,
receiverId: talentId,
message: payload.message,
}),
);

navigation.dispatch(
StackActions.replace(RootScreenName.CHAT, {
partnerName: profileName,
partnerId: talentId,
chatId: talentId,
}),
);
}
},
[profileName, navigation, dispatch, currentUserData?.id, talentId],
[dispatch, currentUserData?.id, talentId],
);

const handleContactClose = useCallback((): void => {
navigation.goBack();
}, [navigation]);

const isLoading = dataStatus === DataStatus.PENDING;

return (
<>
<Overlay isActive={isLoading} />
Expand Down

0 comments on commit faaeac0

Please sign in to comment.