diff --git a/components/ChatView/MessageView.tsx b/components/ChatView/MessageView.tsx index 3d131e4..d32dcf4 100644 --- a/components/ChatView/MessageView.tsx +++ b/components/ChatView/MessageView.tsx @@ -1,7 +1,9 @@ -import { ReactElement } from "react"; +import { Menu, MenuItem } from "@mui/material"; +import { ReactElement, useState } from "react"; +import { toast } from "react-hot-toast"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; -import { useUserStore } from "@/store"; +import { useMessageStore, useUserStore } from "@/store"; import { Message } from "@/types"; import Icon from "../Icon"; import { CodeBlock } from "../CodeBlock"; @@ -13,11 +15,33 @@ interface Props { const MessageView = (props: Props) => { const message = props.message; const userStore = useUserStore(); + const messageStore = useMessageStore(); + const [menuAnchorEl, setMenuAnchorEl] = useState(null); const isCurrentUser = message.creatorId === userStore.currentUser.id; + const showMenu = Boolean(menuAnchorEl); + + const handleMoreMenuClick = (event: React.MouseEvent) => { + if (menuAnchorEl) { + setMenuAnchorEl(null); + } else { + setMenuAnchorEl(event.currentTarget); + } + }; + + const copyMessage = () => { + navigator.clipboard.writeText(message.content); + toast.success("Copied to clipboard"); + setMenuAnchorEl(null); + }; + + const deleteMessage = (message: Message) => { + messageStore.clearMessage((item) => item.id !== message.id); + setMenuAnchorEl(null); + }; return (
@@ -36,7 +60,7 @@ const MessageView = (props: Props) => {
{ const match = /language-(\w+)/.exec(child.props.className || ""); const language = match ? match[1] : "text"; return ( -
+                  
                      {
           >
             {message.content}
           
+          
+ + setMenuAnchorEl(null)} + MenuListProps={{ + "aria-labelledby": "basic-button", + }} + > + + + Copy + + deleteMessage(message)}> + + Delete + + +
)} diff --git a/components/ChatView/index.tsx b/components/ChatView/index.tsx index ccdffc0..74798f2 100644 --- a/components/ChatView/index.tsx +++ b/components/ChatView/index.tsx @@ -150,7 +150,7 @@ const ChatView = () => { className="drawer-content relative w-full h-full max-h-full flex flex-col justify-start items-start overflow-y-auto bg-white" >
-
+
{messageList.length === 0 ? ( ) : ( @@ -158,7 +158,7 @@ const ChatView = () => { )} {isRequesting && }
-
+
diff --git a/pages/api/chat.ts b/pages/api/chat.ts index dfc4e6c..01232cf 100644 --- a/pages/api/chat.ts +++ b/pages/api/chat.ts @@ -17,7 +17,7 @@ const handler = async (req: NextRequest) => { body: JSON.stringify({ model: "gpt-3.5-turbo", messages: reqBody.messages, - max_tokens: 2000, + max_tokens: 1000, temperature: 0, frequency_penalty: 0.0, presence_penalty: 0.0,