diff --git a/components/messages/message-chat-action.tsx b/components/messages/message-chat-action.tsx new file mode 100644 index 0000000..f7a87a2 --- /dev/null +++ b/components/messages/message-chat-action.tsx @@ -0,0 +1,46 @@ +import { Copy, Trash2 } from "lucide-react"; +import { Button } from "../ui/button"; +import { Id } from "@/convex/_generated/dataModel"; +import useApiMutation from "@/lib/hooks/use-api-mutation"; +import { api } from "@/convex/_generated/api"; +import { toast } from "sonner"; + +type MessageChatActionProps = { + messageId: Id<"messages">; + content: string; +}; + +const MessageChatAction = ({ content, messageId }: MessageChatActionProps) => { + const { mutate: deleteMessage, isPending } = useApiMutation( + api.message.remove + ); + + const handleCopy = () => { + navigator.clipboard.writeText(content); + toast.success("Message copied to clipboard"); + }; + + const handleDelete = () => { + deleteMessage({ messageId }) + .then(() => toast.success("Message deleted")) + .catch(() => toast.error("Failed to delete message")); + }; + + return ( + <> + + + > + ); +}; + +export default MessageChatAction; diff --git a/components/messages/message-chat.tsx b/components/messages/message-chat.tsx index 046877a..b2d63a5 100644 --- a/components/messages/message-chat.tsx +++ b/components/messages/message-chat.tsx @@ -3,6 +3,7 @@ import { useCurrentUser } from "@/lib/hooks/use-current-user"; import { cn } from "@/lib/utils"; import Hint from "../hint"; import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"; +import MessageChatAction from "./message-chat-action"; type MessageChatProps = { message: Doc<"messages">; @@ -13,7 +14,7 @@ const MessageChat = ({ message }: MessageChatProps) => { return (
{message.content}