Add export and delete buttons back to ProjectDetailsDialog, remove export from title menu

This commit is contained in:
Alex Gleason committed 2025-12-26 00:23:52 -06:00
1 parent 6542b55823
commit 2743d42b55
4 files changed
+223 -154

No files matched your search

+62
View File
@@ -0,0 +1,62 @@
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
AlertDialogTrigger,
} from '@/components/ui/alert-dialog';
import { Loader2 } from 'lucide-react';
import type { ReactNode } from 'react';
interface DeleteProjectDialogProps {
projectName: string;
onDelete: () => void | Promise<void>;
isDeleting: boolean;
open?: boolean;
onOpenChange?: (open: boolean) => void;
trigger?: ReactNode;
}
export function DeleteProjectDialog({
projectName,
onDelete,
isDeleting,
open,
onOpenChange,
trigger,
}: DeleteProjectDialogProps) {
return (
<AlertDialog open={open} onOpenChange={onOpenChange}>
{trigger && <AlertDialogTrigger asChild>{trigger}</AlertDialogTrigger>}
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete Project</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to delete "{projectName}"? This action cannot be undone and will permanently delete all project data including files.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={onDelete}
disabled={isDeleting}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{isDeleting ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Deleting...
</>
) : (
'Delete Project'
)}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
);
}
+142 -1
View File
@@ -23,20 +23,28 @@ import {
DollarSign,
ExternalLink,
FileCode,
Download,
Trash2,
} from 'lucide-react';
import { Skeleton } from './ui/skeleton';
import { Separator } from './ui/separator';
import { DotAI } from '@/lib/DotAI';
import { LabelSelector } from '@/components/labels/LabelSelector';
import { DeleteProjectDialog } from '@/components/DeleteProjectDialog';
import { cn } from '@/lib/utils';
import JSZip from 'jszip';
interface ProjectDetailsDialogProps {
project: Project;
open: boolean;
onOpenChange: (open: boolean) => void;
onProjectDeleted?: () => void;
}
export function ProjectDetailsDialog({ project, open, onOpenChange }: ProjectDetailsDialogProps) {
export function ProjectDetailsDialog({ project, open, onOpenChange, onProjectDeleted }: ProjectDetailsDialogProps) {
const [isRenaming, setIsRenaming] = useState(false);
const [isExporting, setIsExporting] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
const [newProjectName, setNewProjectName] = useState(project.id);
const [totalCost, setTotalCost] = useState<number | null>(null);
const [isLoading, setIsLoading] = useState(false);
@@ -129,6 +137,105 @@ export function ProjectDetailsDialog({ project, open, onOpenChange }: ProjectDet
}
};
const handleDeleteProject = async () => {
setIsDeleting(true);
try {
await projectsManager.deleteProject(project.id);
// Invalidate the projects query to update the sidebar
await queryClient.invalidateQueries({ queryKey: ['projects'] });
toast({
title: "Project deleted",
description: `"${project.name}" has been permanently deleted.`,
});
// Close the dialog first
onOpenChange(false);
// Navigate back to home and notify parent
navigate('/');
if (onProjectDeleted) {
onProjectDeleted();
}
} catch (error) {
toast({
title: "Failed to delete project",
description: error instanceof Error ? error.message : "An unexpected error occurred",
variant: "destructive",
});
} finally {
setIsDeleting(false);
}
};
const handleExportProject = async () => {
setIsExporting(true);
try {
const zip = new JSZip();
const projectPath = `${projectsPath}/${project.id}`;
// Recursive function to add files and directories to zip from a specific project
const addFolderToZip = async (dirPath: string, zipFolder: JSZip) => {
try {
const entries = await fs.readdir(dirPath, { withFileTypes: true });
for (const entry of entries) {
const fullPath = `${dirPath}/${entry.name}`;
if (entry.isDirectory()) {
// Create folder in zip and recursively add its contents
const folder = zipFolder.folder(entry.name);
if (folder) {
await addFolderToZip(fullPath, folder);
}
} else if (entry.isFile()) {
// Add file to zip
try {
const fileContent = await fs.readFile(fullPath);
zipFolder.file(entry.name, fileContent);
} catch (error) {
console.warn(`Failed to read file ${fullPath}:`, error);
}
}
}
} catch (error) {
console.warn(`Failed to read directory ${dirPath}:`, error);
}
};
// Start from the project directory
await addFolderToZip(projectPath, zip);
// Generate zip file
const content = await zip.generateAsync({ type: 'blob' });
// Create download link
const url = URL.createObjectURL(content);
const link = document.createElement('a');
link.href = url;
link.download = `${project.id}.zip`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
toast({
title: "Project exported successfully",
description: `"${project.name}" has been downloaded as a zip file.`,
});
} catch (error) {
console.error('Failed to export project:', error);
toast({
title: "Failed to export project",
description: error instanceof Error ? error.message : "An unexpected error occurred",
variant: "destructive",
});
} finally {
setIsExporting(false);
}
};
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-md" onOpenAutoFocus={(e) => e.preventDefault()}>
@@ -223,6 +330,40 @@ export function ProjectDetailsDialog({ project, open, onOpenChange }: ProjectDet
{/* Labels */}
<LabelSelector projectId={project.id} />
<Separator />
{/* Export Project Button */}
<Button
onClick={handleExportProject}
disabled={isExporting || isDeleting || isRenaming}
className="w-full gap-2"
variant="outline"
>
{isExporting ? (
<Loader2 className="h-4 w-4 animate-spin" />
) : (
<Download className="h-4 w-4" />
)}
{isExporting ? 'Exporting...' : 'Export Project'}
</Button>
{/* Delete Project Button */}
<DeleteProjectDialog
projectName={project.name}
onDelete={handleDeleteProject}
isDeleting={isDeleting}
trigger={
<Button
variant="destructive"
className="w-full gap-2"
disabled={isExporting || isDeleting || isRenaming}
>
<Trash2 className="h-4 w-4" />
Delete Project
</Button>
}
/>
</div>
</DialogContent>
</Dialog>
-12
View File
@@ -12,7 +12,6 @@ import {
Folder,
Copy,
ChevronDown,
Download,
Trash2,
Star,
} from 'lucide-react';
@@ -26,7 +25,6 @@ interface ProjectTitleMenuProps {
onNewChat: () => void;
onGitHistory: () => void;
onDuplicate: () => void;
onExport: () => void;
onDelete: () => void;
onProjectDetails: () => void;
isAILoading: boolean;
@@ -40,7 +38,6 @@ export function ProjectTitleMenu({
onNewChat,
onGitHistory,
onDuplicate,
onExport,
onDelete,
onProjectDetails,
isAILoading,
@@ -130,15 +127,6 @@ export function ProjectTitleMenu({
{t('duplicateProject')}
</DropdownMenuItem>
<DropdownMenuItem
onClick={onExport}
disabled={isAnyLoading}
className="gap-2"
>
<Download className="h-4 w-4" />
Export Project
</DropdownMenuItem>
<DropdownMenuItem
onClick={onDelete}
disabled={isAnyLoading}
+19 -141
View File
@@ -7,19 +7,10 @@ import { ChatPane, type ChatPaneRef } from '@/components/Shakespeare/ChatPane';
import { PreviewPane } from '@/components/Shakespeare/PreviewPane';
import { ProjectSidebar } from '@/components/ProjectSidebar';
import { ProjectDetailsDialog } from '@/components/ProjectDetailsDialog';
import { DeleteProjectDialog } from '@/components/DeleteProjectDialog';
import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@/components/ui/resizable';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from '@/components/ui/alert-dialog';
import { ArrowLeft, MessageSquare, Eye, Code, Menu, Loader2 } from 'lucide-react';
import { useNavigate } from 'react-router-dom';
import { useIsMobile } from '@/hooks/useIsMobile';
@@ -34,11 +25,9 @@ import { useIsProjectPreviewable } from '@/hooks/useIsProjectPreviewable';
import { useConsoleError } from '@/hooks/useConsoleError';
import { useAutoBuild } from '@/hooks/useAutoBuild';
import { useToast } from '@/hooks/useToast';
import { useFS } from '@/hooks/useFS';
import { useFSPaths } from '@/hooks/useFSPaths';
import { useGitFetch } from '@/hooks/useGitFetch';
import { useQueryClient } from '@tanstack/react-query';
import JSZip from 'jszip';
import { cn } from '@/lib/utils';
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
@@ -54,7 +43,6 @@ export function ProjectView() {
const [gitHistoryOpen, setGitHistoryOpen] = useState(false);
const [duplicateDialogOpen, setDuplicateDialogOpen] = useState(false);
const [deleteDialogOpen, setDeleteDialogOpen] = useState(false);
const [isExporting, setIsExporting] = useState(false);
const [isDeleting, setIsDeleting] = useState(false);
// Use console error state from provider
@@ -65,7 +53,6 @@ export function ProjectView() {
const navigate = useNavigate();
const isMobile = useIsMobile();
const { toast } = useToast();
const { fs } = useFS();
const { projectsPath } = useFSPaths();
const queryClient = useQueryClient();
@@ -154,75 +141,6 @@ export function ProjectView() {
navigate('/');
};
const handleExportProject = async () => {
if (!project) return;
setIsExporting(true);
try {
const zip = new JSZip();
const projectPath = `${projectsPath}/${project.id}`;
// Recursive function to add files and directories to zip from a specific project
const addFolderToZip = async (dirPath: string, zipFolder: JSZip) => {
try {
const entries = await fs.readdir(dirPath, { withFileTypes: true });
for (const entry of entries) {
const fullPath = `${dirPath}/${entry.name}`;
if (entry.isDirectory()) {
// Create folder in zip and recursively add its contents
const folder = zipFolder.folder(entry.name);
if (folder) {
await addFolderToZip(fullPath, folder);
}
} else if (entry.isFile()) {
// Add file to zip
try {
const fileContent = await fs.readFile(fullPath);
zipFolder.file(entry.name, fileContent);
} catch (error) {
console.warn(`Failed to read file ${fullPath}:`, error);
}
}
}
} catch (error) {
console.warn(`Failed to read directory ${dirPath}:`, error);
}
};
// Start from the project directory
await addFolderToZip(projectPath, zip);
// Generate zip file
const content = await zip.generateAsync({ type: 'blob' });
// Create download link
const url = URL.createObjectURL(content);
const link = document.createElement('a');
link.href = url;
link.download = `${project.id}.zip`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
toast({
title: "Project exported successfully",
description: `"${project.name}" has been downloaded as a zip file.`,
});
} catch (error) {
console.error('Failed to export project:', error);
toast({
title: "Failed to export project",
description: error instanceof Error ? error.message : "An unexpected error occurred",
variant: "destructive",
});
} finally {
setIsExporting(false);
}
};
const handleDeleteProject = async () => {
if (!project) return;
@@ -293,11 +211,10 @@ export function ProjectView() {
onNewChat={handleNewChat}
onGitHistory={() => setGitHistoryOpen(true)}
onDuplicate={() => setDuplicateDialogOpen(true)}
onExport={handleExportProject}
onDelete={() => setDeleteDialogOpen(true)}
onProjectDetails={() => setIsProjectDetailsOpen(true)}
isAILoading={isAILoading}
isAnyLoading={isAnyLoading || isExporting || isDeleting}
isAnyLoading={isAnyLoading || isDeleting}
className="text-base"
/>
) : (
@@ -446,6 +363,7 @@ export function ProjectView() {
project={project}
open={isProjectDetailsOpen}
onOpenChange={setIsProjectDetailsOpen}
onProjectDeleted={handleProjectDeleted}
/>
<GitHistoryDialog
projectId={project.id}
@@ -458,33 +376,13 @@ export function ProjectView() {
open={duplicateDialogOpen}
onOpenChange={setDuplicateDialogOpen}
/>
<AlertDialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete Project</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to delete "{project.name}"? This action cannot be undone and will permanently delete all project data including files.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleDeleteProject}
disabled={isDeleting}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{isDeleting ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Deleting...
</>
) : (
'Delete Project'
)}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<DeleteProjectDialog
projectName={project.name}
onDelete={handleDeleteProject}
isDeleting={isDeleting}
open={deleteDialogOpen}
onOpenChange={setDeleteDialogOpen}
/>
</>
)}
</div>
@@ -543,11 +441,10 @@ export function ProjectView() {
onNewChat={handleNewChat}
onGitHistory={() => setGitHistoryOpen(true)}
onDuplicate={() => setDuplicateDialogOpen(true)}
onExport={handleExportProject}
onDelete={() => setDeleteDialogOpen(true)}
onProjectDetails={() => setIsProjectDetailsOpen(true)}
isAILoading={isAILoading}
isAnyLoading={isAnyLoading || isExporting || isDeleting}
isAnyLoading={isAnyLoading || isDeleting}
className="text-lg"
/>
) : (
@@ -638,6 +535,7 @@ export function ProjectView() {
project={project}
open={isProjectDetailsOpen}
onOpenChange={setIsProjectDetailsOpen}
onProjectDeleted={handleProjectDeleted}
/>
<GitHistoryDialog
projectId={project.id}
@@ -650,33 +548,13 @@ export function ProjectView() {
open={duplicateDialogOpen}
onOpenChange={setDuplicateDialogOpen}
/>
<AlertDialog open={deleteDialogOpen} onOpenChange={setDeleteDialogOpen}>
<AlertDialogContent>
<AlertDialogHeader>
<AlertDialogTitle>Delete Project</AlertDialogTitle>
<AlertDialogDescription>
Are you sure you want to delete "{project.name}"? This action cannot be undone and will permanently delete all project data including files.
</AlertDialogDescription>
</AlertDialogHeader>
<AlertDialogFooter>
<AlertDialogCancel>Cancel</AlertDialogCancel>
<AlertDialogAction
onClick={handleDeleteProject}
disabled={isDeleting}
className="bg-destructive text-destructive-foreground hover:bg-destructive/90"
>
{isDeleting ? (
<>
<Loader2 className="h-4 w-4 mr-2 animate-spin" />
Deleting...
</>
) : (
'Delete Project'
)}
</AlertDialogAction>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
<DeleteProjectDialog
projectName={project.name}
onDelete={handleDeleteProject}
isDeleting={isDeleting}
open={deleteDialogOpen}
onOpenChange={setDeleteDialogOpen}
/>
</>
)}
</div>