From 15843f59c964f94d2466ae386e1ae83ee044e6c9 Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Sat, 9 Dec 2023 18:06:03 -0600 Subject: [PATCH] init 4 --- .../common/components/FeedItem/context.ts | 2 +- .../ProfileContent/ProfileContent.tsx | 2 +- .../ChatChannelItem/ChatChannelItem.tsx | 10 +++--- .../DirectMessageModal/DirectMessageModal.tsx | 33 ++++++++++++------- .../FeedItemBaseContent.tsx | 11 ++++--- src/services/Proposal.ts | 4 +-- .../hooks/useCases/useDMUserChatChannel.ts | 8 ++--- 7 files changed, 40 insertions(+), 30 deletions(-) diff --git a/src/pages/common/components/FeedItem/context.ts b/src/pages/common/components/FeedItem/context.ts index bc4db7e5c2..edac1a35b6 100644 --- a/src/pages/common/components/FeedItem/context.ts +++ b/src/pages/common/components/FeedItem/context.ts @@ -44,7 +44,7 @@ export interface FeedItemBaseContentProps { hasImages?: boolean; isLoading?: boolean; shouldHideBottomContent?: boolean; - dmUserId?: string; + dmUserIds?: string[]; hasUnseenMention?: boolean; notion?: CommonNotion; } diff --git a/src/pages/commonFeed/components/FeedLayout/components/ProfileContent/ProfileContent.tsx b/src/pages/commonFeed/components/FeedLayout/components/ProfileContent/ProfileContent.tsx index 99b64f0d26..75cdeaaceb 100644 --- a/src/pages/commonFeed/components/FeedLayout/components/ProfileContent/ProfileContent.tsx +++ b/src/pages/commonFeed/components/FeedLayout/components/ProfileContent/ProfileContent.tsx @@ -83,7 +83,7 @@ const ProfileContent: FC = (props) => { if (onDMClick) { onDMClick(); } else { - fetchDMUserChatChannel(userId); + fetchDMUserChatChannel([userId]); } }; diff --git a/src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx b/src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx index 9d9880c345..a4a06f2519 100644 --- a/src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx +++ b/src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx @@ -30,14 +30,14 @@ export const ChatChannelItem: FC = (props) => { useChatContext(); const user = useSelector(selectUser()); const userId = user?.uid; - const dmUserId = + const dmUserIds = chatChannel.participants.length === 1 ? chatChannel.participants[0] : chatChannel.participants.filter( (participant) => participant !== userId, )[0]; const dmUserName = getUserName(dmUser); - const finalTitle = dmUserName; + const finalTitle = chatChannel.participants.length > 1 ? "Group" : dmUserName; const handleOpenChat = useCallback(() => { setChatItem({ @@ -82,8 +82,8 @@ export const ChatChannelItem: FC = (props) => { useChatChannelSubscription(chatChannel.id, userId, handleChatChannelUpdate); useEffect(() => { - fetchDMUser(dmUserId); - }, [dmUserId]); + fetchDMUser(dmUserIds); + }, [dmUserIds]); useEffect(() => { fetchChatChannelUserStatus({ @@ -129,7 +129,7 @@ export const ChatChannelItem: FC = (props) => { ownerId={userId} renderImage={renderImage} isImageRounded - dmUserId={dmUserId} + dmUserIds={[dmUserIds]} /> ); }; diff --git a/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.tsx b/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.tsx index 5d413d5139..a9134a20c5 100644 --- a/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.tsx +++ b/src/pages/inbox/components/DirectMessageButton/components/DirectMessageModal/DirectMessageModal.tsx @@ -1,12 +1,11 @@ -import React, { FC, ReactElement, useEffect } from "react"; +import React, { FC, ReactElement, useEffect, useState } from "react"; import { useDispatch } from "react-redux"; import Select from "react-select"; import { Modal, UserAvatar } from "@/shared/components"; import { useDMUserChatChannel } from "@/shared/hooks/useCases"; import useThemeColor from "@/shared/hooks/useThemeColor"; import { SearchIcon } from "@/shared/icons"; -import { DMUser } from "@/shared/interfaces"; -import { Button, Loader } from "@/shared/ui-kit"; +import { Button, ButtonVariant, Loader } from "@/shared/ui-kit"; import { emptyFunction } from "@/shared/utils"; import { inboxActions } from "@/store/states"; import { selectorStyles } from "./components/selectorStyles"; @@ -22,8 +21,8 @@ interface DirectMessageModalProps { interface SelectOption { value: string; - user: DMUser; label: JSX.Element; + uid: string; } const DirectMessageModal: FC = (props) => { @@ -48,9 +47,10 @@ const DirectMessageModal: FC = (props) => { resetDMUserChatChannel, error: isChannelLoadedWithError, } = useDMUserChatChannel(); + const [groupUids, setGroupUids] = useState([]); - const handleUserItemClick = (item: DMUser) => { - fetchDMUserChatChannel(item.uid); + const handleChatCreate = (uid: string[]) => { + fetchDMUserChatChannel(uid); }; useEffect(() => { @@ -89,7 +89,6 @@ const DirectMessageModal: FC = (props) => { const options: SelectOption[] = dmUsers.map((user) => ({ value: user.userName, - user: user, label: (
= (props) => { {user.userName}
), + uid: user.uid, })); - const handleClick = (item: SelectOption) => { + const handleItemClick = (selectedItems) => { if (!groupMessage) { - handleUserItemClick(item.user); + handleChatCreate([selectedItems.uid]); } else { - console.log("HANDLE GROUP MESSAGE"); + const uids = selectedItems.map((item) => item.uid); + setGroupUids(uids); } }; return ( <> + {groupMessage && ( + + )}