From ca53c80e3eb1ce7961b3d06bd5ffcad3bc3051ec Mon Sep 17 00:00:00 2001 From: PopDaph Date: Mon, 2 Oct 2023 16:21:05 +0200 Subject: [PATCH] Dynamic load emoji data --- .../conversation/ConversationMessage.tsx | 42 ++++++++++++------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/front/components/assistant/conversation/ConversationMessage.tsx b/front/components/assistant/conversation/ConversationMessage.tsx index 8a0eac021cd6d..f9f7943db1176 100644 --- a/front/components/assistant/conversation/ConversationMessage.tsx +++ b/front/components/assistant/conversation/ConversationMessage.tsx @@ -1,8 +1,7 @@ import { Avatar, Button, DropdownMenu } from "@dust-tt/sparkle"; import { Emoji, EmojiMartData } from "@emoji-mart/data"; -import data from "@emoji-mart/data"; import Picker from "@emoji-mart/react"; -import { ComponentType, MouseEventHandler } from "react"; +import { ComponentType, MouseEventHandler, useEffect, useState } from "react"; import React from "react"; import { mutate } from "swr"; @@ -42,6 +41,18 @@ export function ConversationMessage({ reactions: MessageReactionType[]; avatarBusy?: boolean; }) { + const [emojiData, setEmojiData] = useState(null); + + useEffect(() => { + async function loadEmojiData() { + const mod = await import("@emoji-mart/data"); + const data: EmojiMartData = mod.default as EmojiMartData; + setEmojiData(data); + } + + void loadEmojiData(); + }, []); + const handleSelectEmoji = async ({ emoji, isToRemove, @@ -94,7 +105,10 @@ export function ConversationMessage({ {reactions.map((reaction) => { const hasReacted = reaction.users.find((u) => u.userId === user.id) !== undefined; - + const emoji = emojiData?.emojis[reaction.emoji]; + if (!emoji) { + return null; + } return ( @@ -145,12 +159,12 @@ export function ConversationMessage({ type="menu" variant="tertiary" size="xs" - label="🔥  👎  🤩" + label="🔥  ❌  🤩" /> { const reaction = reactions.find( (r) => r.emoji === emojiData.id @@ -175,30 +189,28 @@ export function ConversationMessage({ } function Reacji({ - id, count, isHighlighted, + emoji, }: { - id: string; count: number; isHighlighted: boolean; + emoji: Emoji; }) { - const allEmojisData: EmojiMartData = data as EmojiMartData; - const emojiData = allEmojisData.emojis[id]; - const emoji = emojiData.skins[0].native; - if (!emoji) { + const nativeEmoji = emoji.skins[0].native; + if (!nativeEmoji) { return null; } return ( - - {emoji}{" "} + + {nativeEmoji}  -  {count} + {count} );