(props: Props)
| 18 | } |
| 19 | |
| 20 | const MessageView = (props: Props) => { |
| 21 | const message = props.message; |
| 22 | const { data: session } = useSession(); |
| 23 | const { t } = useTranslation(); |
| 24 | const settingStore = useSettingStore(); |
| 25 | const userStore = useUserStore(); |
| 26 | const conversationStore = useConversationStore(); |
| 27 | const connectionStore = useConnectionStore(); |
| 28 | const messageStore = useMessageStore(); |
| 29 | const isCurrentUser = message.creatorId === userStore.currentUser.id; |
| 30 | const connection = connectionStore.getConnectionById(conversationStore.getConversationById(message.conversationId)?.connectionId || ""); |
| 31 | |
| 32 | const copyMessage = () => { |
| 33 | navigator.clipboard.writeText(message.content); |
| 34 | toast.success("Copied to clipboard"); |
| 35 | }; |
| 36 | |
| 37 | const deleteMessage = (message: Message) => { |
| 38 | messageStore.clearMessage((item) => item.id !== message.id); |
| 39 | }; |
| 40 | |
| 41 | return ( |
| 42 | <div |
| 43 | className={`w-full max-w-full flex flex-row justify-start items-start my-4 group ${ |
| 44 | isCurrentUser ? "justify-end sm:pl-24" : "sm:pr-24" |
| 45 | }`} |
| 46 | > |
| 47 | {isCurrentUser ? ( |
| 48 | <> |
| 49 | <div className="invisible group-hover:visible"> |
| 50 | <Dropdown |
| 51 | tigger={ |
| 52 | <button className="w-6 h-6 mr-1 mt-2 shrink-0 flex justify-center items-center text-gray-400 hover:text-gray-500"> |
| 53 | <Icon.IoMdMore className="w-5 h-auto" /> |
| 54 | </button> |
| 55 | } |
| 56 | > |
| 57 | <div className="p-1 flex flex-col justify-start items-start bg-white dark:bg-zinc-900 rounded-lg"> |
| 58 | <DropdownItem |
| 59 | className="w-full p-1 px-2 flex flex-row justify-start items-center rounded-lg cursor-pointer hover:bg-gray-100 dark:hover:bg-zinc-800" |
| 60 | onClick={copyMessage} |
| 61 | > |
| 62 | <Icon.BiClipboard className="w-4 h-auto mr-2 opacity-70" /> |
| 63 | {t("common.copy")} |
| 64 | </DropdownItem> |
| 65 | <DropdownItem |
| 66 | className="w-full p-1 px-2 flex flex-row justify-start items-center rounded-lg cursor-pointer hover:bg-gray-100 dark:hover:bg-zinc-800" |
| 67 | onClick={() => deleteMessage(message)} |
| 68 | > |
| 69 | <Icon.BiTrash className="w-4 h-auto mr-2 opacity-70" /> |
| 70 | {t("common.delete")} |
| 71 | </DropdownItem> |
| 72 | </div> |
| 73 | </Dropdown> |
| 74 | </div> |
| 75 | <div className="w-auto max-w-[calc(100%-2rem)] flex flex-col justify-start items-start"> |
| 76 | <div className="w-full bg-indigo-600 text-white dark:text-gray-200 px-4 py-2 rounded-lg whitespace-pre-wrap break-all"> |
| 77 | {message.content} |
nothing calls this directly
no test coverage detected