From 3beee3cc28b609d8d1b4e478c9542ef9b6d964bd Mon Sep 17 00:00:00 2001 From: BetaHuhn Date: Mon, 28 Aug 2023 18:27:59 +0200 Subject: [PATCH] expanded message actions --- src/components/CreatePromptModal.tsx | 2 +- src/components/MessageItem.tsx | 73 +++++++++++++++++----------- 2 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/components/CreatePromptModal.tsx b/src/components/CreatePromptModal.tsx index 70bd778..67e5509 100644 --- a/src/components/CreatePromptModal.tsx +++ b/src/components/CreatePromptModal.tsx @@ -27,7 +27,7 @@ export function CreatePromptModal({ content }: { content?: string }) { return ( <> {content ? ( - + diff --git a/src/components/MessageItem.tsx b/src/components/MessageItem.tsx index f3d5bc3..01f4249 100644 --- a/src/components/MessageItem.tsx +++ b/src/components/MessageItem.tsx @@ -1,21 +1,24 @@ import { ActionIcon, Box, + Button, Card, Code, + Collapse, CopyButton, Flex, Table, Text, ThemeIcon, Tooltip, + Transition, } from "@mantine/core"; -import { useClipboard } from "@mantine/hooks"; -import { IconCopy, IconUser } from "@tabler/icons-react"; -import { useMemo } from "react"; +import { useClickOutside, useClipboard } from "@mantine/hooks"; +import { IconCopy, IconInfoCircle, IconTrash, IconUser } from "@tabler/icons-react"; +import { useMemo, useState } from "react"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; -import { Message } from "../db"; +import { Message, detaDB } from "../db"; import "../styles/markdown.scss"; import { CreatePromptModal } from "./CreatePromptModal"; import { LogoIcon } from "./Logo"; @@ -28,9 +31,17 @@ export function MessageItem({ message }: { message: Message }) { return matches ? matches.length : 0; }, [message.content]); + const [isExpanded, setExpanded] = useState(false); + const ref = useClickOutside(() => setExpanded(false)); + + const handleDelete = async () => { + await detaDB.messages.delete(message.key); + setExpanded(false); + } + return ( - + setExpanded(true)} style={{ cursor: 'pointer' }}> {message.role === "user" && ( @@ -71,32 +82,36 @@ export function MessageItem({ message }: { message: Message }) { ), }} /> - {message.role === "assistant" && ( - - - {wordCount} words - - - )} - - - - - {({ copied, copy }) => ( - - - - - - )} - - {/* - - - - */} + + + + + + {wordCount} words + + + + + + + {({ copied, copy }) => ( + + + + + + )} + + + + + + + + + );