From 04ac660d61d3d7f20cd4bd4a4210d09e393528e7 Mon Sep 17 00:00:00 2001 From: "claude[bot]" <209825114+claude[bot]@users.noreply.github.com> Date: Tue, 10 Jun 2025 17:12:30 +0000 Subject: [PATCH 01/11] feat: Add advanced message actions with tooltips - Add regenerate, delete, and copy actions for assistant messages - Add edit, delete, and copy actions for user messages - Implement small, always-present tooltips (copy shows only on hover) - Add proper state management for message operations - Support inline editing for user messages with save/cancel buttons - Regenerate function deletes assistant message and resends last user message Fixes #106 Co-authored-by: AnthonyRonning --- frontend/src/routes/_auth.chat.$chatId.tsx | 388 +++++++++++++++++++-- 1 file changed, 359 insertions(+), 29 deletions(-) diff --git a/frontend/src/routes/_auth.chat.$chatId.tsx b/frontend/src/routes/_auth.chat.$chatId.tsx index 606b6b0c5..b94cfbec2 100644 --- a/frontend/src/routes/_auth.chat.$chatId.tsx +++ b/frontend/src/routes/_auth.chat.$chatId.tsx @@ -1,6 +1,17 @@ import { useEffect, useRef, useState, useCallback } from "react"; import { createFileRoute } from "@tanstack/react-router"; -import { AsteriskIcon, Check, Copy, UserIcon, ChevronDown, Bot, SquarePenIcon } from "lucide-react"; +import { + AsteriskIcon, + Check, + Copy, + UserIcon, + ChevronDown, + Bot, + SquarePenIcon, + RotateCcw, + Trash2, + Edit3 +} from "lucide-react"; import ChatBox from "@/components/ChatBox"; import { useOpenAI } from "@/ai/useOpenAi"; import { useLocalState } from "@/state/useLocalState"; @@ -13,6 +24,8 @@ import { Button } from "@/components/ui/button"; import { BillingStatus } from "@/billing/billingApi"; import { useNavigate, useLocation } from "@tanstack/react-router"; import { useIsMobile } from "@/utils/utils"; +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip"; +import { Textarea } from "@/components/ui/textarea"; export const Route = createFileRoute("/_auth/chat/$chatId")({ component: ChatComponent @@ -35,15 +48,140 @@ function useCopyToClipboard(text: string) { return { isCopied, handleCopy }; } -function UserMessage({ text, chatId }: { text: string; chatId: string }) { +function UserMessage({ + text, + chatId, + messageIndex, + onEdit, + onDelete, + onCopy +}: { + text: string; + chatId: string; + messageIndex: number; + onEdit: (index: number, newText: string) => void; + onDelete: (index: number) => void; + onCopy: (text: string) => void; +}) { + const [isEditing, setIsEditing] = useState(false); + const [editText, setEditText] = useState(text); + const [isCopied, setIsCopied] = useState(false); + + const handleEdit = () => { + if (isEditing) { + onEdit(messageIndex, editText); + setIsEditing(false); + } else { + setIsEditing(true); + } + }; + + const handleCancel = () => { + setEditText(text); + setIsEditing(false); + }; + + const handleCopy = useCallback(async () => { + try { + await navigator.clipboard.writeText(text); + onCopy(text); + setIsCopied(true); + setTimeout(() => setIsCopied(false), 2000); + } catch (error) { + console.error("Failed to copy text: ", error); + } + }, [text, onCopy]); + + const handleDelete = () => { + onDelete(messageIndex); + }; return ( -
+
-
- +
+ {isEditing ? ( +
+