From 4f552334b231d8608ecee51b4d212e8eed24f893 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 3 Dec 2025 01:40:28 -0600 Subject: [PATCH] Allow deleting a chat --- src/components/ActionsMenu.tsx | 46 ++++++++--- src/components/DeleteChatDialog.tsx | 99 +++++++++++++++++++++++ src/pages/ChatView.tsx | 118 +++++++++++++++++++++++++--- 3 files changed, 240 insertions(+), 23 deletions(-) create mode 100644 src/components/DeleteChatDialog.tsx diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx index 59c2d4a3..638d118c 100644 --- a/src/components/ActionsMenu.tsx +++ b/src/components/ActionsMenu.tsx @@ -13,10 +13,12 @@ import { History, Folder, Rocket, + Trash2, } from 'lucide-react'; import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; import { GitDialog } from '@/components/GitDialog'; import { DeployDialog } from '@/components/DeployDialog'; +import { DeleteChatDialog } from '@/components/DeleteChatDialog'; interface ActionsMenuProps { projectId: string; @@ -28,6 +30,7 @@ interface ActionsMenuProps { disabled?: boolean; onFirstInteraction?: () => void; isChat?: boolean; // Flag to indicate this is a chat, not a project + onChatDeleted?: () => void; // Callback when a chat is deleted } export function ActionsMenu({ @@ -40,10 +43,12 @@ export function ActionsMenu({ disabled = false, onFirstInteraction: _onFirstInteraction, isChat = false, + onChatDeleted, }: ActionsMenuProps) { const [gitHistoryOpen, setGitHistoryOpen] = useState(false); const [gitDialogOpen, setGitDialogOpen] = useState(false); const [deployDialogOpen, setDeployDialogOpen] = useState(false); + const [deleteChatOpen, setDeleteChatOpen] = useState(false); const isAnyLoading = isLoading || isBuildLoading; @@ -64,17 +69,26 @@ export function ActionsMenu({ - - - New Chat - - - {!isChat && ( + {isChat ? ( + setDeleteChatOpen(true)} + disabled={isLoading} + className="gap-2 text-destructive focus:text-destructive" + > + + Delete Chat + + ) : ( <> + + + New Chat + + setGitHistoryOpen(true)} disabled={isAnyLoading} @@ -112,8 +126,6 @@ export function ActionsMenu({ )} - - @@ -141,6 +153,16 @@ export function ActionsMenu({ )} + {/* Delete Chat Dialog - only show for chats */} + {isChat && ( + + )} ); } \ No newline at end of file diff --git a/src/components/DeleteChatDialog.tsx b/src/components/DeleteChatDialog.tsx new file mode 100644 index 00000000..f36fc92c --- /dev/null +++ b/src/components/DeleteChatDialog.tsx @@ -0,0 +1,99 @@ +import { useState } from 'react'; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from '@/components/ui/alert-dialog'; +import { useChatsManager } from '@/hooks/useChatsManager'; +import { useToast } from '@/hooks/useToast'; +import { useQueryClient } from '@tanstack/react-query'; +import { Loader2 } from 'lucide-react'; + +interface DeleteChatDialogProps { + chatId: string; + chatName: string; + open: boolean; + onOpenChange: (open: boolean) => void; + onDeleted?: () => void; +} + +export function DeleteChatDialog({ + chatId, + chatName, + open, + onOpenChange, + onDeleted, +}: DeleteChatDialogProps) { + const [isDeleting, setIsDeleting] = useState(false); + const chatsManager = useChatsManager(); + const { toast } = useToast(); + const queryClient = useQueryClient(); + + const handleDelete = async () => { + setIsDeleting(true); + + try { + await chatsManager.deleteChat(chatId); + + // Invalidate the chats query to refresh the sidebar + await queryClient.invalidateQueries({ queryKey: ['chats'] }); + + toast({ + title: 'Chat deleted', + description: `${chatName} has been deleted successfully.`, + }); + + onOpenChange(false); + + // Call the onDeleted callback if provided + if (onDeleted) { + onDeleted(); + } + } catch (error) { + console.error('Failed to delete chat:', error); + toast({ + title: 'Error', + description: 'Failed to delete chat. Please try again.', + variant: 'destructive', + }); + } finally { + setIsDeleting(false); + } + }; + + return ( + + + + Delete Chat + + Are you sure you want to delete "{chatName}"? This action cannot be undone and all + messages will be permanently deleted. + + + + Cancel + + {isDeleting ? ( + <> + + Deleting... + + ) : ( + 'Delete' + )} + + + + + ); +} diff --git a/src/pages/ChatView.tsx b/src/pages/ChatView.tsx index 2b34a33b..b6a00ea2 100644 --- a/src/pages/ChatView.tsx +++ b/src/pages/ChatView.tsx @@ -60,21 +60,115 @@ export function ChatView() { // when isAILoading becomes true after user interaction }; - const handleChatDeleted = async () => { - setChat(null); + const handleChatDeleted = () => { + // Navigate to home page after chat is deleted navigate('/'); }; + // Chat not found - show in app layout with sidebar if (!chat && !isLoading) { - return ( -
-
-

Chat Not Found

- + if (isMobile) { + return ( +
+
+
+
+ +
Chat Not Found
+
+
+
+ + {/* Mobile Sidebar Overlay */} + {isSidebarVisible && ( +
+
setIsSidebarVisible(false)} + /> +
+ {}} + onClose={() => setIsSidebarVisible(false)} + /> +
+
+ )} + +
+
+

Chat Not Found

+

+ This chat may have been deleted or doesn't exist. +

+ +
+
+ ); + } + + // Desktop layout for not found + return ( +
+ + {isSidebarVisible && ( + <> + + {}} + onToggleSidebar={() => setIsSidebarVisible(false)} + /> + + + + )} + + +
+
+
+
+ {!isSidebarVisible && ( + + )} +
Chat Not Found
+
+
+
+ +
+
+

Chat Not Found

+

+ This chat may have been deleted or doesn't exist. +

+ +
+
+
+
+
); } @@ -113,6 +207,7 @@ export function ChatView() { isBuildLoading={false} onFirstInteraction={handleFirstInteraction} isChat={true} + onChatDeleted={handleChatDeleted} /> ) : ( @@ -129,7 +224,7 @@ export function ChatView() { className="absolute inset-0" onClick={() => setIsSidebarVisible(false)} /> - + {/* Sidebar */}
) : (