From bd9a261c04ead1aa4c6ab1adaf2bd229314b44a1 Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Mon, 1 Apr 2024 10:57:56 -0300 Subject: [PATCH 01/27] init --- src/services/DiscussionMessage.ts | 34 ++++++----- .../Chat/ChatMessage/ChatMessage.tsx | 5 +- .../ReactWithEmoji/ReactWithEmoji.tsx | 4 +- .../components/Reactions/Reactions.tsx | 56 ++++++++++++++++++- src/shared/hooks/useCases/useUserReaction.ts | 25 +++++---- 5 files changed, 94 insertions(+), 30 deletions(-) diff --git a/src/services/DiscussionMessage.ts b/src/services/DiscussionMessage.ts index f1b859a95..647fe04af 100644 --- a/src/services/DiscussionMessage.ts +++ b/src/services/DiscussionMessage.ts @@ -185,20 +185,28 @@ class DiscussionMessageService { await Api.post(ApiEndpoint.DeleteDiscussionMessageReaction, payload); }; - public getUserReaction = async ( + public getUsersReactions = async ( discussionMsgId: string, - userId: string, - ): Promise => - ( - await firebase - .firestore() - .collection(Collection.DiscussionMessage) - .doc(discussionMsgId) - .collection(Collection.Reactions) - .withConverter(getUserReactionConverter) - .doc(userId) - .get() - ).data() || null; + userId?: string, + fetchAll?: boolean, + ): Promise => { + const reactionsRef = firebase + .firestore() + .collection(Collection.DiscussionMessage) + .doc(discussionMsgId) + .collection(Collection.Reactions) + .withConverter(getUserReactionConverter); + + if (fetchAll) { + const snapshot = await reactionsRef.get(); + const reactions = snapshot.docs.map((doc) => doc.data()); + return reactions; + } + + const doc = await reactionsRef.doc(userId).get(); + const reaction = doc.exists ? doc.data() : null; + return reaction ? [reaction] : null; + }; } export default new DiscussionMessageService(); diff --git a/src/shared/components/Chat/ChatMessage/ChatMessage.tsx b/src/shared/components/Chat/ChatMessage/ChatMessage.tsx index ce780d200..3ee5ee28a 100644 --- a/src/shared/components/Chat/ChatMessage/ChatMessage.tsx +++ b/src/shared/components/Chat/ChatMessage/ChatMessage.tsx @@ -556,7 +556,10 @@ export default function ChatMessage({ )} {!isSystemMessage && isUserDiscussionMessage && ( - + )} diff --git a/src/shared/components/Chat/ChatMessage/components/ReactWithEmoji/ReactWithEmoji.tsx b/src/shared/components/Chat/ChatMessage/components/ReactWithEmoji/ReactWithEmoji.tsx index 64055bb58..35c3b3929 100644 --- a/src/shared/components/Chat/ChatMessage/components/ReactWithEmoji/ReactWithEmoji.tsx +++ b/src/shared/components/Chat/ChatMessage/components/ReactWithEmoji/ReactWithEmoji.tsx @@ -58,7 +58,7 @@ export const ReactWithEmoji: FC = (props) => { const { isOutside, setOutsideValue } = useOutsideClick(wrapperRef); const { reactToDiscussionMessage } = useDiscussionMessageReaction(); const { reactToChatMessage } = useChatMessageReaction(); - const { getUserReaction, getDMUserReaction } = useUserReaction(); + const { getUserReaction, getDMUserReaction } = useUserReaction({}); useEffect(() => { if (isOutside) { @@ -76,7 +76,7 @@ export const ReactWithEmoji: FC = (props) => { const userReaction = await getUserReaction(discussionMessageId); if (isMounted) { - setUserReaction(userReaction); + setUserReaction(userReaction?.[0]); } } else if (chatMessageId && chatChannelId) { const userReaction = await getDMUserReaction( diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx index 5271a69c1..d4d06af88 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx @@ -1,14 +1,64 @@ -import React, { FC } from "react"; +import React, { FC, useEffect, useState } from "react"; import { isEmpty } from "lodash"; -import { ReactionCounts } from "@/shared/models"; +import { useUserReaction, useUsersByIds } from "@/shared/hooks/useCases"; +import { ReactionCounts, UserReaction } from "@/shared/models"; import styles from "./Reactions.module.scss"; interface ReactionsProps { reactions?: ReactionCounts | null; + discussionMessageId?: string; } export const Reactions: FC = (props) => { - const { reactions } = props; + const { reactions, discussionMessageId } = props; + const { getUserReaction } = useUserReaction({ fetchAll: true }); + const { fetchUsers, data: users } = useUsersByIds(); + const [usersReactions, setUsersReactions] = useState< + UserReaction[] | null | undefined + >(null); + + if (usersReactions) { + console.log(usersReactions); + } + + if (users) { + console.log(users); + } + + useEffect(() => { + let isMounted = true; + + (async () => { + if (discussionMessageId) { + const usersReactions = await getUserReaction(discussionMessageId); + + if (isMounted) { + setUsersReactions(usersReactions as UserReaction[]); + } + } + + // else if (chatMessageId && chatChannelId) { + // const userReaction = await getDMUserReaction( + // chatMessageId, + // chatChannelId, + // ); + + // if (isMounted) { + // setUserReaction(userReaction); + // } + // } + })(); + + return () => { + isMounted = false; + }; + }, [discussionMessageId]); // , chatMessageId, chatChannelId + + useEffect(() => { + if (usersReactions) { + fetchUsers(usersReactions.map((user) => user.userId)); + } + }, [usersReactions]); if (!reactions || isEmpty(reactions)) { return null; diff --git a/src/shared/hooks/useCases/useUserReaction.ts b/src/shared/hooks/useCases/useUserReaction.ts index b62de5e1f..6e8e5c23f 100644 --- a/src/shared/hooks/useCases/useUserReaction.ts +++ b/src/shared/hooks/useCases/useUserReaction.ts @@ -7,28 +7,31 @@ import { UserReaction } from "@/shared/models"; interface Return { getUserReaction: ( discussionMessageId: string, - ) => Promise; + ) => Promise; getDMUserReaction: ( chatMessageId: string, chatChannelId: string, ) => Promise; } -export const useUserReaction = (): Return => { +interface Options { + fetchAll?: boolean; +} + +export const useUserReaction = ({ fetchAll }: Options): Return => { const user = useSelector(selectUser()); const userId = user?.uid; const getUserReaction = useCallback( async (discussionMessageId: string) => { - if (userId) { - try { - return await DiscussionMessageService.getUserReaction( - discussionMessageId, - userId, - ); - } catch (error) { - Logger.error(error); - } + try { + return await DiscussionMessageService.getUsersReactions( + discussionMessageId, + userId, + fetchAll, + ); + } catch (error) { + Logger.error(error); } }, [userId], From 358d5e643a491838f942fc025504ed86905c6fc6 Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Mon, 1 Apr 2024 14:59:17 -0300 Subject: [PATCH 02/27] init 2 --- .../Reactions/Reactions.module.scss | 31 +++++++++++++ .../components/Reactions/Reactions.tsx | 46 ++++++++++++++----- 2 files changed, 65 insertions(+), 12 deletions(-) diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss index f64db1b4e..03690c8ba 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss @@ -13,3 +13,34 @@ .totalCount { margin-right: 0.25rem; } + +.reactionsTooltipTrigger { + border: none; + background-color: var(--secondary-background); +} + +.reactionsTooltipContent { + z-index: 999; + min-width: 1rem; + min-height: 1rem; + background-color: var(--primary-background); +} + +.listItem { + display: flex; + align-items: center; + margin: 0.5rem 0; + //border: 0.0625rem solid var(--gentle-stroke); +} + +.userAvatar { + margin-right: 0.5rem; +} + +.listUsername { + margin-right: 0.5rem; +} + +.listItemEmoji { + margin-left: auto; +} diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx index d4d06af88..a0e3076df 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx @@ -1,7 +1,9 @@ -import React, { FC, useEffect, useState } from "react"; +import React, { FC, useEffect, useMemo, useState } from "react"; import { isEmpty } from "lodash"; +import { UserAvatar } from "@/shared/components/UserAvatar"; import { useUserReaction, useUsersByIds } from "@/shared/hooks/useCases"; import { ReactionCounts, UserReaction } from "@/shared/models"; +import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui-kit"; import styles from "./Reactions.module.scss"; interface ReactionsProps { @@ -12,19 +14,11 @@ interface ReactionsProps { export const Reactions: FC = (props) => { const { reactions, discussionMessageId } = props; const { getUserReaction } = useUserReaction({ fetchAll: true }); - const { fetchUsers, data: users } = useUsersByIds(); + const { fetchUsers, data: users, fetched } = useUsersByIds(); const [usersReactions, setUsersReactions] = useState< UserReaction[] | null | undefined >(null); - if (usersReactions) { - console.log(usersReactions); - } - - if (users) { - console.log(users); - } - useEffect(() => { let isMounted = true; @@ -52,7 +46,7 @@ export const Reactions: FC = (props) => { return () => { isMounted = false; }; - }, [discussionMessageId]); // , chatMessageId, chatChannelId + }, [discussionMessageId, reactions]); // , chatMessageId, chatChannelId useEffect(() => { if (usersReactions) { @@ -74,12 +68,40 @@ export const Reactions: FC = (props) => { .filter((key) => reactions[key] > 0) .map((emoji, index) => {emoji}); + const list = useMemo(() => { + if (users) { + return users.map((user) => { + const userReaction = usersReactions?.find( + (elem) => elem.userId === user.uid, + )?.emoji; + return ( +
+ + {user.displayName} + {userReaction} +
+ ); + }); + } + }, [users, usersReactions]); + return (
{totalCount > 1 && ( {totalCount} )} - {emojis} + + + {emojis} + + + {!fetched && !users && "Loading..."} + {fetched && list} + +
); }; From 4579d95a7d84c52e2e2592c741263d9de46476a7 Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Mon, 1 Apr 2024 15:10:08 -0300 Subject: [PATCH 03/27] init 3 --- src/services/Chat.ts | 34 ++++++++++++------- .../Chat/ChatMessage/DMChatMessage.tsx | 6 +++- .../ReactWithEmoji/ReactWithEmoji.tsx | 2 +- .../Reactions/Reactions.module.scss | 1 + .../components/Reactions/Reactions.tsx | 31 +++++++++-------- src/shared/hooks/useCases/useUserReaction.ts | 3 +- 6 files changed, 47 insertions(+), 30 deletions(-) diff --git a/src/services/Chat.ts b/src/services/Chat.ts index 62582b5fb..01762d291 100644 --- a/src/services/Chat.ts +++ b/src/services/Chat.ts @@ -434,19 +434,27 @@ class ChatService { chatMessageId: string, chatChannelId: string, userId: string, - ): Promise => - ( - await firebase - .firestore() - .collection(Collection.ChatChannel) - .doc(chatChannelId) - .collection(SubCollections.ChatMessages) - .doc(chatMessageId) - .collection(Collection.Reactions) - .withConverter(getUserReactionConverter) - .doc(userId) - .get() - ).data() || null; + fetchAll?: boolean, + ): Promise => { + const reactionsRef = firebase + .firestore() + .collection(Collection.ChatChannel) + .doc(chatChannelId) + .collection(SubCollections.ChatMessages) + .doc(chatMessageId) + .collection(Collection.Reactions) + .withConverter(getUserReactionConverter); + + if (fetchAll) { + const snapshot = await reactionsRef.get(); + const reactions = snapshot.docs.map((doc) => doc.data()); + return reactions; + } + + const doc = await reactionsRef.doc(userId).get(); + const reaction = doc.exists ? doc.data() : null; + return reaction ? [reaction] : null; + }; } export default new ChatService(); diff --git a/src/shared/components/Chat/ChatMessage/DMChatMessage.tsx b/src/shared/components/Chat/ChatMessage/DMChatMessage.tsx index 78b8c93b4..59a10bceb 100644 --- a/src/shared/components/Chat/ChatMessage/DMChatMessage.tsx +++ b/src/shared/components/Chat/ChatMessage/DMChatMessage.tsx @@ -598,7 +598,11 @@ export default function DMChatMessage({ )} {isUserDiscussionMessage && ( - + )} diff --git a/src/shared/components/Chat/ChatMessage/components/ReactWithEmoji/ReactWithEmoji.tsx b/src/shared/components/Chat/ChatMessage/components/ReactWithEmoji/ReactWithEmoji.tsx index 35c3b3929..7b7f96e1d 100644 --- a/src/shared/components/Chat/ChatMessage/components/ReactWithEmoji/ReactWithEmoji.tsx +++ b/src/shared/components/Chat/ChatMessage/components/ReactWithEmoji/ReactWithEmoji.tsx @@ -85,7 +85,7 @@ export const ReactWithEmoji: FC = (props) => { ); if (isMounted) { - setUserReaction(userReaction); + setUserReaction(userReaction?.[0]); } } })(); diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss index 03690c8ba..16439885a 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss @@ -24,6 +24,7 @@ min-width: 1rem; min-height: 1rem; background-color: var(--primary-background); + box-shadow: 0 0.25rem 0.9375rem var(--drop-shadow); } .listItem { diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx index a0e3076df..7e51f019f 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx @@ -9,11 +9,16 @@ import styles from "./Reactions.module.scss"; interface ReactionsProps { reactions?: ReactionCounts | null; discussionMessageId?: string; + chatMessageId?: string; + chatChannelId?: string; } export const Reactions: FC = (props) => { - const { reactions, discussionMessageId } = props; - const { getUserReaction } = useUserReaction({ fetchAll: true }); + const { reactions, discussionMessageId, chatMessageId, chatChannelId } = + props; + const { getUserReaction, getDMUserReaction } = useUserReaction({ + fetchAll: true, + }); const { fetchUsers, data: users, fetched } = useUsersByIds(); const [usersReactions, setUsersReactions] = useState< UserReaction[] | null | undefined @@ -29,24 +34,22 @@ export const Reactions: FC = (props) => { if (isMounted) { setUsersReactions(usersReactions as UserReaction[]); } - } - - // else if (chatMessageId && chatChannelId) { - // const userReaction = await getDMUserReaction( - // chatMessageId, - // chatChannelId, - // ); + } else if (chatMessageId && chatChannelId) { + const userReaction = await getDMUserReaction( + chatMessageId, + chatChannelId, + ); - // if (isMounted) { - // setUserReaction(userReaction); - // } - // } + if (isMounted) { + setUsersReactions(userReaction as UserReaction[]); + } + } })(); return () => { isMounted = false; }; - }, [discussionMessageId, reactions]); // , chatMessageId, chatChannelId + }, [discussionMessageId, chatMessageId, chatChannelId, reactions]); useEffect(() => { if (usersReactions) { diff --git a/src/shared/hooks/useCases/useUserReaction.ts b/src/shared/hooks/useCases/useUserReaction.ts index 6e8e5c23f..27da17d5c 100644 --- a/src/shared/hooks/useCases/useUserReaction.ts +++ b/src/shared/hooks/useCases/useUserReaction.ts @@ -11,7 +11,7 @@ interface Return { getDMUserReaction: ( chatMessageId: string, chatChannelId: string, - ) => Promise; + ) => Promise; } interface Options { @@ -45,6 +45,7 @@ export const useUserReaction = ({ fetchAll }: Options): Return => { chatMessageId, chatChannelId, userId, + fetchAll, ); } catch (error) { Logger.error(error); From e6a44f18aa10e22257475d3f38efdd2d3f7d925f Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Mon, 1 Apr 2024 19:19:25 -0300 Subject: [PATCH 04/27] finlaize --- .../ChatMessage/components/Reactions/Reactions.module.scss | 7 +++++-- .../Chat/ChatMessage/components/Reactions/Reactions.tsx | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss index 16439885a..58e44ea54 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss @@ -25,17 +25,20 @@ min-height: 1rem; background-color: var(--primary-background); box-shadow: 0 0.25rem 0.9375rem var(--drop-shadow); + padding: 0; } .listItem { display: flex; align-items: center; - margin: 0.5rem 0; - //border: 0.0625rem solid var(--gentle-stroke); + padding: 0.5rem 0; + border-bottom: 0.0625rem solid var(--gentle-stroke); } .userAvatar { margin-right: 0.5rem; + width: 2rem; + height: 2rem; } .listUsername { diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx index 7e51f019f..71366a5cc 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx @@ -32,7 +32,7 @@ export const Reactions: FC = (props) => { const usersReactions = await getUserReaction(discussionMessageId); if (isMounted) { - setUsersReactions(usersReactions as UserReaction[]); + setUsersReactions(usersReactions); } } else if (chatMessageId && chatChannelId) { const userReaction = await getDMUserReaction( @@ -41,7 +41,7 @@ export const Reactions: FC = (props) => { ); if (isMounted) { - setUsersReactions(userReaction as UserReaction[]); + setUsersReactions(userReaction); } } })(); From b4af19026cdf9556f04a77a7cfaec124e3a25548 Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Tue, 2 Apr 2024 16:24:00 -0300 Subject: [PATCH 05/27] use chat users instead of using the hook to get them --- .../Chat/ChatMessage/ChatMessage.tsx | 1 + .../Chat/ChatMessage/DMChatMessage.tsx | 1 + .../components/Reactions/Reactions.tsx | 59 ++++++++++--------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/src/shared/components/Chat/ChatMessage/ChatMessage.tsx b/src/shared/components/Chat/ChatMessage/ChatMessage.tsx index 3ee5ee28a..24d69f95c 100644 --- a/src/shared/components/Chat/ChatMessage/ChatMessage.tsx +++ b/src/shared/components/Chat/ChatMessage/ChatMessage.tsx @@ -559,6 +559,7 @@ export default function ChatMessage({ )} diff --git a/src/shared/components/Chat/ChatMessage/DMChatMessage.tsx b/src/shared/components/Chat/ChatMessage/DMChatMessage.tsx index 59a10bceb..c41099330 100644 --- a/src/shared/components/Chat/ChatMessage/DMChatMessage.tsx +++ b/src/shared/components/Chat/ChatMessage/DMChatMessage.tsx @@ -602,6 +602,7 @@ export default function DMChatMessage({ reactions={finalReactionCounts} chatMessageId={discussionMessage.id} chatChannelId={chatChannelId} + users={users} /> )} diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx index 71366a5cc..d10d64c72 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx @@ -1,8 +1,10 @@ import React, { FC, useEffect, useMemo, useState } from "react"; +import { useSelector } from "react-redux"; import { isEmpty } from "lodash"; +import { selectUser } from "@/pages/Auth/store/selectors"; import { UserAvatar } from "@/shared/components/UserAvatar"; -import { useUserReaction, useUsersByIds } from "@/shared/hooks/useCases"; -import { ReactionCounts, UserReaction } from "@/shared/models"; +import { useUserReaction } from "@/shared/hooks/useCases"; +import { ReactionCounts, User, UserReaction } from "@/shared/models"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui-kit"; import styles from "./Reactions.module.scss"; @@ -11,15 +13,22 @@ interface ReactionsProps { discussionMessageId?: string; chatMessageId?: string; chatChannelId?: string; + users?: User[]; } export const Reactions: FC = (props) => { - const { reactions, discussionMessageId, chatMessageId, chatChannelId } = - props; + const { + reactions, + discussionMessageId, + chatMessageId, + chatChannelId, + users, + } = props; + const currentUser = useSelector(selectUser()); + const { getUserReaction, getDMUserReaction } = useUserReaction({ fetchAll: true, }); - const { fetchUsers, data: users, fetched } = useUsersByIds(); const [usersReactions, setUsersReactions] = useState< UserReaction[] | null | undefined >(null); @@ -51,12 +60,6 @@ export const Reactions: FC = (props) => { }; }, [discussionMessageId, chatMessageId, chatChannelId, reactions]); - useEffect(() => { - if (usersReactions) { - fetchUsers(usersReactions.map((user) => user.userId)); - } - }, [usersReactions]); - if (!reactions || isEmpty(reactions)) { return null; } @@ -71,22 +74,25 @@ export const Reactions: FC = (props) => { .filter((key) => reactions[key] > 0) .map((emoji, index) => {emoji}); - const list = useMemo(() => { - if (users) { - return users.map((user) => { - const userReaction = usersReactions?.find( + const usersList = useMemo(() => { + if (users && usersReactions && currentUser) { + return [...users, currentUser].map((user, index) => { + const userReaction = usersReactions.find( (elem) => elem.userId === user.uid, )?.emoji; - return ( -
- - {user.displayName} - {userReaction} -
- ); + + if (userReaction) { + return ( +
+ + {user.displayName} + {userReaction} +
+ ); + } }); } }, [users, usersReactions]); @@ -101,8 +107,7 @@ export const Reactions: FC = (props) => { {emojis} - {!fetched && !users && "Loading..."} - {fetched && list} + {usersList ? usersList : "Loading..."} From de007156e7950930e13ce56cdbeb4cd8056aafd5 Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Fri, 5 Apr 2024 18:04:08 -0300 Subject: [PATCH 06/27] tooltip trigger is now by click and not hover ; code review updates --- .../Reactions/Reactions.module.scss | 1 + .../components/Reactions/Reactions.tsx | 100 ++++++++++++------ 2 files changed, 69 insertions(+), 32 deletions(-) diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss index 58e44ea54..6d06af0c0 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.module.scss @@ -17,6 +17,7 @@ .reactionsTooltipTrigger { border: none; background-color: var(--secondary-background); + cursor: pointer; } .reactionsTooltipContent { diff --git a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx index d10d64c72..2e9585e4b 100644 --- a/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx +++ b/src/shared/components/Chat/ChatMessage/components/Reactions/Reactions.tsx @@ -1,8 +1,17 @@ -import React, { FC, useEffect, useMemo, useState } from "react"; +import React, { + FC, + MouseEventHandler, + useEffect, + useMemo, + useRef, + useState, +} from "react"; import { useSelector } from "react-redux"; import { isEmpty } from "lodash"; import { selectUser } from "@/pages/Auth/store/selectors"; +import { Logger } from "@/services"; import { UserAvatar } from "@/shared/components/UserAvatar"; +import { useOutsideClick } from "@/shared/hooks"; import { useUserReaction } from "@/shared/hooks/useCases"; import { ReactionCounts, User, UserReaction } from "@/shared/models"; import { Tooltip, TooltipContent, TooltipTrigger } from "@/shared/ui-kit"; @@ -25,6 +34,11 @@ export const Reactions: FC = (props) => { users, } = props; const currentUser = useSelector(selectUser()); + const [isOpen, setIsOpen] = useState(false); + const reactionsListwrapperRef = useRef(null); + const { isOutside, setOutsideValue } = useOutsideClick( + reactionsListwrapperRef, + ); const { getUserReaction, getDMUserReaction } = useUserReaction({ fetchAll: true, @@ -33,25 +47,36 @@ export const Reactions: FC = (props) => { UserReaction[] | null | undefined >(null); + useEffect(() => { + if (isOutside) { + setOutsideValue(); + setIsOpen(false); + } + }, [isOutside]); + useEffect(() => { let isMounted = true; (async () => { - if (discussionMessageId) { - const usersReactions = await getUserReaction(discussionMessageId); + try { + if (discussionMessageId) { + const usersReactions = await getUserReaction(discussionMessageId); - if (isMounted) { - setUsersReactions(usersReactions); - } - } else if (chatMessageId && chatChannelId) { - const userReaction = await getDMUserReaction( - chatMessageId, - chatChannelId, - ); - - if (isMounted) { - setUsersReactions(userReaction); + if (isMounted) { + setUsersReactions(usersReactions); + } + } else if (chatMessageId && chatChannelId) { + const userReaction = await getDMUserReaction( + chatMessageId, + chatChannelId, + ); + + if (isMounted) { + setUsersReactions(userReaction); + } } + } catch (error) { + Logger.error(error); } })(); @@ -60,20 +85,6 @@ export const Reactions: FC = (props) => { }; }, [discussionMessageId, chatMessageId, chatChannelId, reactions]); - if (!reactions || isEmpty(reactions)) { - return null; - } - - const totalCount = Object.values(reactions).reduce((a, b) => a + b, 0); - - if (totalCount === 0) { - return null; - } - - const emojis = Object.keys(reactions) - .filter((key) => reactions[key] > 0) - .map((emoji, index) => {emoji}); - const usersList = useMemo(() => { if (users && usersReactions && currentUser) { return [...users, currentUser].map((user, index) => { @@ -97,17 +108,42 @@ export const Reactions: FC = (props) => { } }, [users, usersReactions]); + if (!reactions || isEmpty(reactions)) { + return null; + } + + const totalCount = Object.values(reactions).reduce((a, b) => a + b, 0); + + if (totalCount === 0) { + return null; + } + + const emojis = Object.keys(reactions) + .filter((key) => reactions[key] > 0) + .map((emoji, index) => {emoji}); + + const toggleReactionsListTooltip: MouseEventHandler = (event) => { + event.stopPropagation(); + setIsOpen((v) => !v); + }; + return (
{totalCount > 1 && ( {totalCount} )} - - + + {emojis} - - {usersList ? usersList : "Loading..."} + + {usersList || "Loading..."}
From 6abac43b1724b7ca235650faeb66ef4c872a1057 Mon Sep 17 00:00:00 2001 From: Roie Natan Date: Fri, 5 Apr 2024 18:16:57 -0300 Subject: [PATCH 07/27] fixes: Old palette remnant --- .../components/NoCommonsInfo/NoCommonsInfo.module.scss | 1 + .../MultipleSpacesLayout/components/Menu/Menu.module.scss | 1 + .../components/SidenavContent/SidenavContent.module.scss | 1 + .../ElementButton/components/LinkModal/LinkModal.tsx | 8 ++++---- 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Navigation/components/CreateCommonPrompt/components/NoCommonsInfo/NoCommonsInfo.module.scss b/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Navigation/components/CreateCommonPrompt/components/NoCommonsInfo/NoCommonsInfo.module.scss index 27e90a266..cea1a76ed 100644 --- a/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Navigation/components/CreateCommonPrompt/components/NoCommonsInfo/NoCommonsInfo.module.scss +++ b/src/shared/layouts/MultipleSpacesLayout/components/Header/components/Navigation/components/CreateCommonPrompt/components/NoCommonsInfo/NoCommonsInfo.module.scss @@ -8,6 +8,7 @@ margin: 0 0 1rem; padding: 0; text-align: center; + color: var(--primary-text); } .createCommonButton { diff --git a/src/shared/layouts/MultipleSpacesLayout/components/Menu/Menu.module.scss b/src/shared/layouts/MultipleSpacesLayout/components/Menu/Menu.module.scss index 2c5cf8cad..cf7b0c4e0 100644 --- a/src/shared/layouts/MultipleSpacesLayout/components/Menu/Menu.module.scss +++ b/src/shared/layouts/MultipleSpacesLayout/components/Menu/Menu.module.scss @@ -11,6 +11,7 @@ margin: 0 0 1rem; padding: 0; text-align: center; + color: var(--primary-text); } .createCommonButton { diff --git a/src/shared/layouts/MultipleSpacesLayout/components/SidenavContent/SidenavContent.module.scss b/src/shared/layouts/MultipleSpacesLayout/components/SidenavContent/SidenavContent.module.scss index e36860d34..d891d8abb 100644 --- a/src/shared/layouts/MultipleSpacesLayout/components/SidenavContent/SidenavContent.module.scss +++ b/src/shared/layouts/MultipleSpacesLayout/components/SidenavContent/SidenavContent.module.scss @@ -22,6 +22,7 @@ margin: 0 0 1rem; padding: 0; text-align: center; + color: var(--primary-text); } .createCommonButton { diff --git a/src/shared/ui-kit/TextEditor/components/ElementButton/components/LinkModal/LinkModal.tsx b/src/shared/ui-kit/TextEditor/components/ElementButton/components/LinkModal/LinkModal.tsx index 1c0d9a67b..44e6f61b9 100644 --- a/src/shared/ui-kit/TextEditor/components/ElementButton/components/LinkModal/LinkModal.tsx +++ b/src/shared/ui-kit/TextEditor/components/ElementButton/components/LinkModal/LinkModal.tsx @@ -8,7 +8,7 @@ import React, { import { Editor } from "slate"; import { Input } from "@/shared/components/Form/Input"; import { Modal } from "@/shared/components/Modal"; -import { Button, ButtonVariant } from "@/shared/ui-kit/Button"; +import { Button, ButtonVariant } from "@/shared/ui-kit"; import { checkIsURL } from "@/shared/utils"; import { ElementType } from "../../../../constants"; import { LinkElement } from "../../../../types"; @@ -96,12 +96,12 @@ const LinkModal: FC = (props) => { />
- {isLinkActive && (