Allow deleting a chat

This commit is contained in:
Alex Gleason committed 2025-12-03 01:40:28 -06:00
1 parent bb9245118c
commit 4f552334b2
3 files changed
+240 -23

No files matched your search

+34 -12
View File
@@ -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({
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-48">
<DropdownMenuItem
onClick={onNewChat}
disabled={isLoading}
className="gap-2"
>
<MessageSquarePlus className="h-4 w-4" />
New Chat
</DropdownMenuItem>
{!isChat && (
{isChat ? (
<DropdownMenuItem
onClick={() => setDeleteChatOpen(true)}
disabled={isLoading}
className="gap-2 text-destructive focus:text-destructive"
>
<Trash2 className="h-4 w-4" />
Delete Chat
</DropdownMenuItem>
) : (
<>
<DropdownMenuItem
onClick={onNewChat}
disabled={isLoading}
className="gap-2"
>
<MessageSquarePlus className="h-4 w-4" />
New Chat
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => setGitHistoryOpen(true)}
disabled={isAnyLoading}
@@ -112,8 +126,6 @@ export function ActionsMenu({
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
@@ -141,6 +153,16 @@ export function ActionsMenu({
</>
)}
{/* Delete Chat Dialog - only show for chats */}
{isChat && (
<DeleteChatDialog
chatId={projectId}
chatName={projectName}
open={deleteChatOpen}
onOpenChange={setDeleteChatOpen}
onDeleted={onChatDeleted}
/>
)}
</>
);
}
+99
View File
@@ -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 (
<AlertDialog open={open} onOpenChange={onOpenChange}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete Chat</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to delete "{chatName}"? This action cannot be undone and all
messages will be permanently deleted.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel disabled={isDeleting}>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleDelete}
disabled={isDeleting}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{isDeleting ? (
<>
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
Deleting...
</>
) : (
'Delete'
)}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}
+107 -11
View File
@@ -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 (
<div className="min-h-screen bg-background flex items-center justify-center">
<div className="text-center">
<h1 className="text-2xl font-bold mb-2">Chat Not Found</h1>
<Button onClick={() => navigate('/')} variant="outline">
<ArrowLeft className="mr-2 h-4 w-4" />
Back to Home
</Button>
if (isMobile) {
return (
<div className="h-dvh flex flex-col bg-background">
<header className="pt-safe bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur">
<div className="h-12 border-b px-4 py-3 flex items-center justify-between">
<div className="flex items-center space-x-2">
<Button
variant="ghost"
size="sm"
onClick={() => setIsSidebarVisible(!isSidebarVisible)}
>
<Menu className="h-4 w-4" />
</Button>
<div className="text-sm font-semibold">Chat Not Found</div>
</div>
</div>
</header>
{/* Mobile Sidebar Overlay */}
{isSidebarVisible && (
<div className="fixed inset-0 z-50 bg-background/80 backdrop-blur-sm">
<div
className="absolute inset-0"
onClick={() => setIsSidebarVisible(false)}
/>
<div className="absolute left-0 top-0 bottom-0 w-64 bg-sidebar">
<ProjectSidebar
selectedProject={null}
onSelectProject={() => {}}
onClose={() => setIsSidebarVisible(false)}
/>
</div>
</div>
)}
<div className="flex-1 flex items-center justify-center p-4">
<div className="text-center">
<h1 className="text-2xl font-bold mb-2">Chat Not Found</h1>
<p className="text-muted-foreground mb-4">
This chat may have been deleted or doesn't exist.
</p>
<Button onClick={() => navigate('/')} variant="outline">
<ArrowLeft className="mr-2 h-4 w-4" />
Back to Home
</Button>
</div>
</div>
</div>
);
}
// Desktop layout for not found
return (
<div className="h-screen flex flex-col bg-background">
<ResizablePanelGroup direction="horizontal">
{isSidebarVisible && (
<>
<ResizablePanel defaultSize={20} minSize={15} maxSize={30}>
<ProjectSidebar
selectedProject={null}
onSelectProject={() => {}}
onToggleSidebar={() => setIsSidebarVisible(false)}
/>
</ResizablePanel>
<ResizableHandle withHandle />
</>
)}
<ResizablePanel defaultSize={isSidebarVisible ? 80 : 100}>
<div className="h-screen flex flex-col">
<header className="pt-safe bg-gradient-to-r from-primary/10 via-accent/5 to-primary/10 backdrop-blur">
<div className="h-12 border-b px-4 py-3 flex items-center justify-between">
<div className="flex items-center space-x-2">
{!isSidebarVisible && (
<Button
variant="ghost"
size="sm"
onClick={() => setIsSidebarVisible(true)}
>
<Menu className="h-4 w-4" />
</Button>
)}
<div className="text-sm font-semibold">Chat Not Found</div>
</div>
</div>
</header>
<div className="flex-1 flex items-center justify-center p-4">
<div className="text-center">
<h1 className="text-2xl font-bold mb-2">Chat Not Found</h1>
<p className="text-muted-foreground mb-4">
This chat may have been deleted or doesn't exist.
</p>
<Button onClick={() => navigate('/')} variant="outline">
<ArrowLeft className="mr-2 h-4 w-4" />
Back to Home
</Button>
</div>
</div>
</div>
</ResizablePanel>
</ResizablePanelGroup>
</div>
);
}
@@ -113,6 +207,7 @@ export function ChatView() {
isBuildLoading={false}
onFirstInteraction={handleFirstInteraction}
isChat={true}
onChatDeleted={handleChatDeleted}
/>
) : (
<Skeleton className="h-8 w-8 rounded" />
@@ -129,7 +224,7 @@ export function ChatView() {
className="absolute inset-0"
onClick={() => setIsSidebarVisible(false)}
/>
{/* Sidebar */}
<div className="absolute left-0 top-0 bottom-0 w-64 bg-sidebar">
<ProjectSidebar
@@ -210,6 +305,7 @@ export function ChatView() {
isBuildLoading={false}
onFirstInteraction={handleFirstInteraction}
isChat={true}
onChatDeleted={handleChatDeleted}
/>
) : (
<Skeleton className="h-8 w-8 rounded" />