Skip to content

Commit

Permalink
init 4
Browse files Browse the repository at this point in the history
  • Loading branch information
roienatan committed Dec 10, 2023
1 parent 5ce3f9f commit 15843f5
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 30 deletions.
2 changes: 1 addition & 1 deletion src/pages/common/components/FeedItem/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export interface FeedItemBaseContentProps {
hasImages?: boolean;
isLoading?: boolean;
shouldHideBottomContent?: boolean;
dmUserId?: string;
dmUserIds?: string[];
hasUnseenMention?: boolean;
notion?: CommonNotion;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ const ProfileContent: FC<ProfileContentProps> = (props) => {
if (onDMClick) {
onDMClick();
} else {
fetchDMUserChatChannel(userId);
fetchDMUserChatChannel([userId]);
}
};

Expand Down
10 changes: 5 additions & 5 deletions src/pages/inbox/components/ChatChannelItem/ChatChannelItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (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({
Expand Down Expand Up @@ -82,8 +82,8 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
useChatChannelSubscription(chatChannel.id, userId, handleChatChannelUpdate);

useEffect(() => {
fetchDMUser(dmUserId);
}, [dmUserId]);
fetchDMUser(dmUserIds);
}, [dmUserIds]);

useEffect(() => {
fetchChatChannelUserStatus({
Expand Down Expand Up @@ -129,7 +129,7 @@ export const ChatChannelItem: FC<ChatChannelFeedLayoutItemProps> = (props) => {
ownerId={userId}
renderImage={renderImage}
isImageRounded
dmUserId={dmUserId}
dmUserIds={[dmUserIds]}
/>
);
};
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -22,8 +21,8 @@ interface DirectMessageModalProps {

interface SelectOption {
value: string;
user: DMUser;
label: JSX.Element;
uid: string;
}

const DirectMessageModal: FC<DirectMessageModalProps> = (props) => {
Expand All @@ -48,9 +47,10 @@ const DirectMessageModal: FC<DirectMessageModalProps> = (props) => {
resetDMUserChatChannel,
error: isChannelLoadedWithError,
} = useDMUserChatChannel();
const [groupUids, setGroupUids] = useState<string[]>([]);

const handleUserItemClick = (item: DMUser) => {
fetchDMUserChatChannel(item.uid);
const handleChatCreate = (uid: string[]) => {
fetchDMUserChatChannel(uid);
};

useEffect(() => {
Expand Down Expand Up @@ -89,7 +89,6 @@ const DirectMessageModal: FC<DirectMessageModalProps> = (props) => {

const options: SelectOption[] = dmUsers.map((user) => ({
value: user.userName,
user: user,
label: (
<div className={styles.optionWrapper}>
<UserAvatar
Expand All @@ -101,20 +100,31 @@ const DirectMessageModal: FC<DirectMessageModalProps> = (props) => {
<span>{user.userName}</span>
</div>
),
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 && (
<Button
onClick={() => handleChatCreate(groupUids)}
variant={ButtonVariant.PrimaryPink}
disabled={!groupUids.length}
>
Create
</Button>
)}
<Select
onChange={(item) => handleClick(item as SelectOption)}
onChange={(selectedItems) => handleItemClick(selectedItems)}
isMulti={groupMessage}
options={options}
placeholder="Search"
Expand All @@ -129,7 +139,6 @@ const DirectMessageModal: FC<DirectMessageModalProps> = (props) => {
IndicatorSeparator: () => null,
}}
/>
{groupMessage && <Button>Create</Button>}
</>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export const FeedItemBaseContent: FC<FeedItemBaseContentProps> = (props) => {
isImageRounded,
isProject,
discussionPredefinedType,
dmUserId,
dmUserIds,
commonId,
hasUnseenMention,
} = props;
Expand All @@ -63,6 +63,7 @@ export const FeedItemBaseContent: FC<FeedItemBaseContentProps> = (props) => {
[styles.imageNonRounded]: !shouldImageBeRounded,
[styles.imageRounded]: shouldImageBeRounded,
});
//const groupMessage = dmUserIds && dmUserIds?.length > 1;

// Here we get either MouseEven, or TouchEven, but I was struggling with importing them from react
// and use here to have correct types.
Expand Down Expand Up @@ -110,8 +111,8 @@ export const FeedItemBaseContent: FC<FeedItemBaseContentProps> = (props) => {
};

const handleAvatarClick = () => {
if (onUserSelect && dmUserId) {
onUserSelect(dmUserId);
if (onUserSelect && dmUserIds) {
onUserSelect(dmUserIds[0]);
} else if (commonId) {
history.push(getCommonPagePath(commonId));
}
Expand Down Expand Up @@ -157,7 +158,7 @@ export const FeedItemBaseContent: FC<FeedItemBaseContentProps> = (props) => {
</p>
</div>
<div className={styles.bottomContent}>
{lastMessage && !checkIsTextEditorValueEmpty(lastMessage) ? (
{/* {lastMessage && !checkIsTextEditorValueEmpty(lastMessage) ? (
<TextEditor
className={styles.lastMessageContainer}
editorClassName={classNames(styles.text, styles.lastMessage, {
Expand All @@ -172,7 +173,7 @@ export const FeedItemBaseContent: FC<FeedItemBaseContentProps> = (props) => {
/>
) : (
<div />
)}
)} */}
<div className={styles.bottomContentRight}>
<FeedCardTags
unreadMessages={unreadMessages}
Expand Down
4 changes: 2 additions & 2 deletions src/services/Proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ class ProposalService {
const proposal = snapshot.data();

if (proposal) {
console.log("proposal found!", proposalId);
//console.log("proposal found!", proposalId);
callback(proposal);
} else {
console.log("proposal was not found", proposalId);
//console.log("proposal was not found", proposalId);
}
});
};
Expand Down
8 changes: 4 additions & 4 deletions src/shared/hooks/useCases/useDMUserChatChannel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { ChatChannel } from "@/shared/models";
interface Return {
loading: boolean;
dmUserChatChannel: ChatChannel | null;
fetchDMUserChatChannel: (dmUserId: string) => void;
fetchDMUserChatChannel: (dmUserId: string[]) => void;
resetDMUserChatChannel: () => void;
error?: boolean;
}
Expand All @@ -21,7 +21,7 @@ export const useDMUserChatChannel = (): Return => {
const userId = user?.uid;

const fetchDMUserChatChannel = useCallback(
async (dmUserId: string) => {
async (dmUserId: string[]) => {
if (!userId) {
return;
}
Expand All @@ -37,13 +37,13 @@ export const useDMUserChatChannel = (): Return => {
try {
dmUserChatChannel = await ChatService.getDMUserChatChannel(
userId,
dmUserId,
dmUserId[0],
);

if (!dmUserChatChannel) {
dmUserChatChannel = await ChatService.createChatChannel([
userId,
dmUserId,
...dmUserId,
]);
}
} catch (error) {
Expand Down

0 comments on commit 15843f5

Please sign in to comment.