diff --git a/frontend/src/routes/_auth.chat.$chatId.tsx b/frontend/src/routes/_auth.chat.$chatId.tsx index 606b6b0c5..cc25827a7 100644 --- a/frontend/src/routes/_auth.chat.$chatId.tsx +++ b/frontend/src/routes/_auth.chat.$chatId.tsx @@ -1,6 +1,18 @@ 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, + GitBranch +} from "lucide-react"; import ChatBox from "@/components/ChatBox"; import { useOpenAI } from "@/ai/useOpenAi"; import { useLocalState } from "@/state/useLocalState"; @@ -9,10 +21,23 @@ import { ChatMessage, Chat, DEFAULT_MODEL_ID } from "@/state/LocalStateContext"; import { AlertDestructive } from "@/components/AlertDestructive"; import { Sidebar, SidebarToggle } from "@/components/Sidebar"; import { useQuery, useQueryClient } from "@tanstack/react-query"; -import { Button } from "@/components/ui/button"; +import { Button, buttonVariants } 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"; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, + AlertDialogTrigger +} from "@/components/ui/alert-dialog"; export const Route = createFileRoute("/_auth/chat/$chatId")({ component: ChatComponent @@ -35,15 +60,207 @@ function useCopyToClipboard(text: string) { return { isCopied, handleCopy }; } -function UserMessage({ text, chatId }: { text: string; chatId: string }) { +function UserMessage({ + text, + chatId, + messageIndex, + onEdit, + onDelete, + onCopy, + onFork +}: { + text: string; + chatId: string; + messageIndex: number; + onEdit: (index: number, newText: string) => void; + onDelete: (index: number) => void; + onCopy: (text: string) => void; + onFork: (index: number) => void; +}) { + const [isEditing, setIsEditing] = useState(false); + const [editText, setEditText] = useState(text); + const [isCopied, setIsCopied] = useState(false); + + // Keep editText in sync with text prop changes (fixes cross-chat state bug) + useEffect(() => { + setEditText(text); + }, [text]); + + 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); + }; + + const handleFork = () => { + onFork(messageIndex); + }; return ( -
+
-
- +
+ {isEditing ? ( +
+