-
-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1022 from The-Commit-Company/develop
Release Version 1.6.9
- Loading branch information
Showing
11 changed files
with
194 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91 changes: 91 additions & 0 deletions
91
frontend/src/components/feature/chat/ChatMessage/ActionModals/ReactionAnalyticsModal.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
import { useMemo } from "react" | ||
import { Flex, Text, Tabs, Box } from "@radix-ui/themes" | ||
import { ReactionObject } from "../MessageReactions" | ||
import { ReactionAnalyticsDialogProps } from "../MessageActions/MessageReactionAnalytics" | ||
import { UserAvatar } from "@/components/common/UserAvatar" | ||
import { useGetUser } from "@/hooks/useGetUser" | ||
|
||
export const ReactionAnalyticsModal = ({ reactions }: ReactionAnalyticsDialogProps) => { | ||
|
||
const { reaction_emojis, all_reacted_members } = useMemo(() => { | ||
const reaction_emojis = reactions.map((reaction: ReactionObject) => reaction.reaction); | ||
const all_reacted_members = reactions.flatMap(({ reaction, users }: ReactionObject) => | ||
users.map((user: string) => ({ user, reaction })) | ||
); | ||
return { reaction_emojis, all_reacted_members }; | ||
}, [reactions]); | ||
|
||
return ( | ||
<> | ||
<Tabs.Root defaultValue="All"> | ||
<Flex direction="column" gap="4"> | ||
<Tabs.List> | ||
<TabTrigger emojiStr="All" /> | ||
{reaction_emojis.map((emojiStr) => { | ||
const reaction = reactions.find((r) => r.reaction === emojiStr); | ||
return <TabTrigger key={emojiStr} emojiStr={emojiStr} count={reaction?.count} />; | ||
})} | ||
</Tabs.List> | ||
<Box> | ||
<Tabs.Content value="All"> | ||
<UserList users={all_reacted_members} /> | ||
</Tabs.Content> | ||
{reactions.map((reaction) => ( | ||
<Tabs.Content key={reaction.reaction} value={reaction.reaction}> | ||
<UserList users={reaction.users.map((user) => ({ user }))} /> | ||
</Tabs.Content> | ||
))} | ||
</Box> | ||
</Flex> | ||
</Tabs.Root> | ||
</> | ||
); | ||
}; | ||
|
||
const TabTrigger = ({ emojiStr, count }: { emojiStr: string; count?: number }) => ( | ||
<Tabs.Trigger value={emojiStr} className="text-gray-11"> | ||
<Flex gap="2" align="center" justify="center"> | ||
<Text size="3">{emojiStr}</Text> | ||
{count && <Text>{count}</Text>} | ||
</Flex> | ||
</Tabs.Trigger> | ||
); | ||
|
||
interface UserItemProps { | ||
user: string; | ||
reaction?: string; | ||
} | ||
const UserList = ({ users }: { users: UserItemProps[] }) => ( | ||
<Box className="overflow-hidden overflow-y-scroll h-[50vh] sm:h-64"> | ||
<Flex direction="column" gap="2"> | ||
<Flex direction="column"> | ||
{users.map((user, index) => ( | ||
<UserItem key={index} user={user.user} reaction={user.reaction} /> | ||
))} | ||
</Flex> | ||
</Flex> | ||
</Box> | ||
); | ||
|
||
const UserItem = ({ user, reaction }: UserItemProps) => { | ||
const userDetails = useGetUser(user) | ||
const userName = userDetails?.full_name ?? user; | ||
|
||
return ( | ||
<Box className="hover:bg-slate-3 rounded-md"> | ||
<Flex align="center" justify="between"> | ||
<Flex className="p-2" gap="3" align="center"> | ||
<UserAvatar src={userDetails?.user_image} size="2" /> | ||
<Text size="2" weight="medium"> | ||
{userName} | ||
</Text> | ||
</Flex> | ||
{reaction && ( | ||
<Text className="pr-3" size="3" weight="medium"> | ||
{reaction} | ||
</Text> | ||
)} | ||
</Flex> | ||
</Box> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
frontend/src/components/feature/chat/ChatMessage/MessageActions/MessageReactionAnalytics.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { useCallback, useState, useMemo } from "react" | ||
import { Message } from "../../../../../../../types/Messaging/Message" | ||
import { Dialog } from "@radix-ui/themes" | ||
import { DIALOG_CONTENT_CLASS } from "@/utils/layout/dialog" | ||
import { useIsDesktop } from "@/hooks/useMediaQuery" | ||
import { Drawer, DrawerContent } from "@/components/layout/Drawer" | ||
import { ReactionObject } from "../MessageReactions" | ||
import { ReactionAnalyticsModal } from "../ActionModals/ReactionAnalyticsModal" | ||
|
||
export const useMessageReactionAnalytics = () => { | ||
const [message, setMessage] = useState<null | Message>(null) | ||
|
||
const message_reactions = message?.message_reactions; | ||
|
||
const reactions: ReactionObject[] = useMemo(() => { | ||
//Parse the string to a JSON object and get an array of reactions | ||
const parsed_json = JSON.parse(message_reactions ?? '{}') as Record<string, ReactionObject> | ||
return Object.values(parsed_json) | ||
}, [message_reactions]) | ||
|
||
const onClose = useCallback(() => { | ||
setMessage(null) | ||
}, []) | ||
|
||
return { | ||
reactions, | ||
message, | ||
onClose, | ||
isOpen: message !== null, | ||
setReactionMessage: setMessage | ||
} | ||
} | ||
|
||
export interface ReactionAnalyticsDialogProps { | ||
isOpen?: boolean, | ||
onClose?: VoidFunction, | ||
reactions: ReactionObject[] | ||
} | ||
export const ReactionAnalyticsDialog = ({ isOpen, onClose, ...reactionProps }: ReactionAnalyticsDialogProps) => { | ||
|
||
const isDesktop = useIsDesktop() | ||
|
||
if (isDesktop) { | ||
return <Dialog.Root open={isOpen} onOpenChange={onClose}> | ||
<Dialog.Content className={`${DIALOG_CONTENT_CLASS} w-[450px]`}> | ||
<ReactionAnalyticsModal {...reactionProps} /> | ||
</Dialog.Content> | ||
</Dialog.Root> | ||
} else { | ||
return <Drawer open={isOpen} onClose={onClose}> | ||
<DrawerContent> | ||
<div className="pb-12"> | ||
<ReactionAnalyticsModal {...reactionProps} /> | ||
</div> | ||
</DrawerContent> | ||
</Drawer> | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
__version__ = "1.6.8" | ||
__version__ = "1.6.9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters