From 0b19ac4f09d850765230ee4665903a626473edf7 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 23 Dec 2025 05:24:01 -0600 Subject: [PATCH] Move deploy button to title bar, favorite button into title menu --- src/components/ActionsMenu.tsx | 139 --------------- src/components/ProjectDetailsDialog.tsx | 176 +------------------ src/components/ProjectTitleMenu.tsx | 85 +++++++-- src/pages/ProjectView.tsx | 220 ++++++++++++++++++++++-- 4 files changed, 279 insertions(+), 341 deletions(-) delete mode 100644 src/components/ActionsMenu.tsx diff --git a/src/components/ActionsMenu.tsx b/src/components/ActionsMenu.tsx deleted file mode 100644 index c2a59ca1..00000000 --- a/src/components/ActionsMenu.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import { useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { Button } from '@/components/ui/button'; -import { - DropdownMenu, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuTrigger, -} from '@/components/ui/dropdown-menu'; -import { - MoreHorizontal, - MessageSquarePlus, - History, - Folder, - Rocket, - Copy, -} from 'lucide-react'; -import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; -import { DeployDialog } from '@/components/DeployDialog'; -import { DuplicateProjectDialog } from '@/components/DuplicateProjectDialog'; - -interface ActionsMenuProps { - projectId: string; - projectName: string; - onNewChat: () => void; - onProjectDetails?: () => void; - isLoading?: boolean; - isBuildLoading?: boolean; - disabled?: boolean; - onFirstInteraction?: () => void; -} - -export function ActionsMenu({ - projectId, - projectName, - onNewChat, - onProjectDetails, - isLoading = false, - isBuildLoading = false, - disabled = false, - onFirstInteraction: _onFirstInteraction, -}: ActionsMenuProps) { - const { t } = useTranslation(); - const [gitHistoryOpen, setGitHistoryOpen] = useState(false); - const [deployDialogOpen, setDeployDialogOpen] = useState(false); - const [duplicateDialogOpen, setDuplicateDialogOpen] = useState(false); - - const isAnyLoading = isLoading || isBuildLoading; - - - - return ( - <> - - - - - - - - New Chat - - - setGitHistoryOpen(true)} - disabled={isAnyLoading} - className="gap-2" - > - - Rollback - - - setDeployDialogOpen(true)} - disabled={isAnyLoading} - className="gap-2" - > - - Deploy - - - setDuplicateDialogOpen(true)} - disabled={isAnyLoading} - className="gap-2" - > - - {t('duplicateProject')} - - - - - Project Details - - - - - - - {/* Dialogs */} - - - - - - - - ); -} \ No newline at end of file diff --git a/src/components/ProjectDetailsDialog.tsx b/src/components/ProjectDetailsDialog.tsx index ab8fc36a..1bb91d41 100644 --- a/src/components/ProjectDetailsDialog.tsx +++ b/src/components/ProjectDetailsDialog.tsx @@ -7,17 +7,6 @@ import { DialogHeader, DialogTitle, } from '@/components/ui/dialog'; -import { - AlertDialog, - AlertDialogAction, - AlertDialogCancel, - AlertDialogContent, - AlertDialogDescription, - AlertDialogFooter, - AlertDialogHeader, - AlertDialogTitle, - AlertDialogTrigger, -} from '@/components/ui/alert-dialog'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; @@ -29,16 +18,12 @@ import { useNavigate } from 'react-router-dom'; import { Calendar, Folder, - Download, Loader2, - Trash2, Save, DollarSign, ExternalLink, FileCode, } from 'lucide-react'; -import JSZip from 'jszip'; -import { Separator } from './ui/separator'; import { Skeleton } from './ui/skeleton'; import { DotAI } from '@/lib/DotAI'; import { LabelSelector } from '@/components/labels/LabelSelector'; @@ -49,11 +34,11 @@ interface ProjectDetailsDialogProps { open: boolean; onOpenChange: (open: boolean) => void; onProjectDeleted?: () => void; + onExportProject?: () => Promise; + onDeleteProject?: () => Promise; } -export function ProjectDetailsDialog({ project, open, onOpenChange, onProjectDeleted }: ProjectDetailsDialogProps) { - const [isExporting, setIsExporting] = useState(false); - const [isDeleting, setIsDeleting] = useState(false); +export function ProjectDetailsDialog({ project, open, onOpenChange, onProjectDeleted, onExportProject, onDeleteProject }: ProjectDetailsDialogProps) { const [isRenaming, setIsRenaming] = useState(false); const [newProjectName, setNewProjectName] = useState(project.id); const [totalCost, setTotalCost] = useState(null); @@ -147,105 +132,6 @@ export function ProjectDetailsDialog({ project, open, onOpenChange, onProjectDel } }; - 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 ( e.preventDefault()}> @@ -340,62 +226,6 @@ export function ProjectDetailsDialog({ project, open, onOpenChange, onProjectDel {/* Labels */} - - - - {/* Export Project Button */} - - - {/* Delete Project Button */} - - - - - - - Delete Project - - Are you sure you want to delete "{project.name}"? This action cannot be undone and will permanently delete all project data including files. - - - - Cancel - - {isDeleting ? ( - <> - - Deleting... - - ) : ( - 'Delete Project' - )} - - - - diff --git a/src/components/ProjectTitleMenu.tsx b/src/components/ProjectTitleMenu.tsx index e576f3e8..63f1c341 100644 --- a/src/components/ProjectTitleMenu.tsx +++ b/src/components/ProjectTitleMenu.tsx @@ -10,18 +10,25 @@ import { MessageSquarePlus, History, Folder, - Rocket, Copy, ChevronDown, + Download, + Trash2, + Star, } from 'lucide-react'; import { cn } from '@/lib/utils'; +import { useLocalStorage } from '@/hooks/useLocalStorage'; +import { useToast } from '@/hooks/useToast'; +import { useQueryClient } from '@tanstack/react-query'; interface ProjectTitleMenuProps { + projectId: string; projectName: string; onNewChat: () => void; onGitHistory: () => void; - onDeploy: () => void; onDuplicate: () => void; + onExport: () => void; + onDelete: () => void; onProjectDetails: () => void; isAILoading: boolean; isAnyLoading: boolean; @@ -29,17 +36,43 @@ interface ProjectTitleMenuProps { } export function ProjectTitleMenu({ + projectId, projectName, onNewChat, onGitHistory, - onDeploy, onDuplicate, + onExport, + onDelete, onProjectDetails, isAILoading, isAnyLoading, className = '', }: ProjectTitleMenuProps) { const { t } = useTranslation(); + const [favorites, setFavorites] = useLocalStorage('project-favorites', []); + const { toast } = useToast(); + const queryClient = useQueryClient(); + + const isFavorite = favorites.includes(projectId); + + const handleToggleFavorite = (e: React.MouseEvent) => { + e.preventDefault(); // Prevent menu from closing + e.stopPropagation(); + + const newFavorites = isFavorite + ? favorites.filter(id => id !== projectId) + : [...favorites, projectId]; + + setFavorites(newFavorites); + + // Invalidate the projects query to trigger a refetch with new sorting + queryClient.invalidateQueries({ queryKey: ['projects'] }); + + toast({ + title: isFavorite ? "Project Unfavorited" : "Project Favorited", + description: `"${projectName}" has been ${isFavorite ? 'removed from' : 'added to'} your favorites.`, + }); + }; return ( @@ -54,12 +87,27 @@ export function ProjectTitleMenu({ e.preventDefault()} // Prevent menu from closing + > + + {isFavorite ? 'Unfavorite' : 'Favorite'} + + + - - New Chat + + Project Details - - Deploy + + New Chat - - Project Details + + Export Project + + + + + Delete Project diff --git a/src/pages/ProjectView.tsx b/src/pages/ProjectView.tsx index eef7ee3a..8d01e9e7 100644 --- a/src/pages/ProjectView.tsx +++ b/src/pages/ProjectView.tsx @@ -10,7 +10,17 @@ import { ProjectDetailsDialog } from '@/components/ProjectDetailsDialog'; import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from '@/components/ui/resizable'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; -import { ArrowLeft, MessageSquare, Eye, Code, Menu } from 'lucide-react'; +import { + AlertDialog, + AlertDialogAction, + AlertDialogCancel, + AlertDialogContent, + AlertDialogDescription, + AlertDialogFooter, + AlertDialogHeader, + AlertDialogTitle, +} from '@/components/ui/alert-dialog'; +import { ArrowLeft, MessageSquare, Eye, Code, Menu, Rocket, Loader2 } from 'lucide-react'; import { useNavigate } from 'react-router-dom'; import { useIsMobile } from '@/hooks/useIsMobile'; import { ProjectTitleMenu } from '@/components/ProjectTitleMenu'; @@ -18,12 +28,16 @@ import { GitHistoryDialog } from '@/components/ai/GitHistoryDialog'; import { DeployDialog } from '@/components/DeployDialog'; import { DuplicateProjectDialog } from '@/components/DuplicateProjectDialog'; import { GitStatusIndicator } from '@/components/GitStatusIndicator'; -import { StarButton } from '@/components/StarButton'; import { GitSyncButton } from '@/components/git-sync'; import { useBuildProject } from '@/hooks/useBuildProject'; 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 { useQueryClient } from '@tanstack/react-query'; +import JSZip from 'jszip'; import { cn } from '@/lib/utils'; export function ProjectView() { @@ -38,6 +52,9 @@ export function ProjectView() { const [gitHistoryOpen, setGitHistoryOpen] = useState(false); const [deployDialogOpen, setDeployDialogOpen] = 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 const { consoleError, dismissConsoleError, clearErrors } = useConsoleError(); @@ -46,6 +63,10 @@ export function ProjectView() { const chatPaneRef = useRef(null); const navigate = useNavigate(); const isMobile = useIsMobile(); + const { toast } = useToast(); + const { fs } = useFS(); + const { projectsPath } = useFSPaths(); + const queryClient = useQueryClient(); const [isSidebarVisible, setIsSidebarVisible] = useState(!isMobile); @@ -128,6 +149,107 @@ 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; + + 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 + setDeleteDialogOpen(false); + + // Navigate back to home and notify parent + navigate('/'); + handleProjectDeleted(); + } catch (error) { + toast({ + title: "Failed to delete project", + description: error instanceof Error ? error.message : "An unexpected error occurred", + variant: "destructive", + }); + } finally { + setIsDeleting(false); + } + }; + const isAnyLoading = isAILoading || build.isPending; if (!project && !isLoading) { @@ -160,14 +282,16 @@ export function ProjectView() {
{project ? ( setGitHistoryOpen(true)} - onDeploy={() => setDeployDialogOpen(true)} onDuplicate={() => setDuplicateDialogOpen(true)} + onExport={handleExportProject} + onDelete={() => setDeleteDialogOpen(true)} onProjectDetails={() => setIsProjectDetailsOpen(true)} isAILoading={isAILoading} - isAnyLoading={isAnyLoading} + isAnyLoading={isAnyLoading || isExporting || isDeleting} className="text-sm" /> ) : ( @@ -183,11 +307,16 @@ export function ProjectView() { projectId={project.id} className="h-8 w-8" /> - setDeployDialogOpen(true)} + disabled={isAnyLoading} className="h-8 w-8" - /> + aria-label="Deploy project" + > + + ) : ( <> @@ -333,6 +462,33 @@ export function ProjectView() { open={duplicateDialogOpen} onOpenChange={setDuplicateDialogOpen} /> + + + + Delete Project + + Are you sure you want to delete "{project.name}"? This action cannot be undone and will permanently delete all project data including files. + + + + Cancel + + {isDeleting ? ( + <> + + Deleting... + + ) : ( + 'Delete Project' + )} + + + + )}
@@ -386,14 +542,16 @@ export function ProjectView() {
{project ? ( setGitHistoryOpen(true)} - onDeploy={() => setDeployDialogOpen(true)} onDuplicate={() => setDuplicateDialogOpen(true)} + onExport={handleExportProject} + onDelete={() => setDeleteDialogOpen(true)} onProjectDetails={() => setIsProjectDetailsOpen(true)} isAILoading={isAILoading} - isAnyLoading={isAnyLoading} + isAnyLoading={isAnyLoading || isExporting || isDeleting} className="text-lg" /> ) : ( @@ -402,7 +560,7 @@ export function ProjectView() {
- {/* Right side - Sync and Star buttons */} + {/* Right side - Deploy and Sync buttons */}
{project ? ( <> @@ -410,11 +568,16 @@ export function ProjectView() { projectId={project.id} className="h-8 w-8" /> - setDeployDialogOpen(true)} + disabled={isAnyLoading} className="h-8 w-8" - /> + aria-label="Deploy project" + > + + ) : ( <> @@ -505,6 +668,33 @@ export function ProjectView() { open={duplicateDialogOpen} onOpenChange={setDuplicateDialogOpen} /> + + + + Delete Project + + Are you sure you want to delete "{project.name}"? This action cannot be undone and will permanently delete all project data including files. + + + + Cancel + + {isDeleting ? ( + <> + + Deleting... + + ) : ( + 'Delete Project' + )} + + + + )}