From 2db9d5e513f8d342e791f919d6008b6a729ef60d Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 27 Sep 2025 15:32:26 -0500 Subject: [PATCH] Move Import ZIP File to Clone page --- src/components/ProjectSidebar.tsx | 42 +++--------------------- src/pages/Clone.tsx | 53 +++++++++++++++++++++++++++++-- 2 files changed, 55 insertions(+), 40 deletions(-) diff --git a/src/components/ProjectSidebar.tsx b/src/components/ProjectSidebar.tsx index 3d6782a0..58d8d00a 100644 --- a/src/components/ProjectSidebar.tsx +++ b/src/components/ProjectSidebar.tsx @@ -1,7 +1,7 @@ -import React, { useEffect, useState } from 'react'; +import React, { useEffect } from 'react'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle, FileArchive } from 'lucide-react'; +import { Plus, Folder, GitBranch, Loader2, ChevronDown, Star, Columns2, X, Settings, HelpCircle } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu'; @@ -9,9 +9,7 @@ import { useProjects } from '@/hooks/useProjects'; import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus'; import { useLocalStorage } from '@/hooks/useLocalStorage'; import { useIsMobile } from '@/hooks/useIsMobile'; -import { ZipImportDialog } from '@/components/ZipImportDialog'; -import { useProjectsManager } from '@/hooks/useProjectsManager'; -import { useToast } from '@/hooks/useToast'; + import type { Project } from '@/lib/ProjectsManager'; import { cn } from '@/lib/utils'; import { useQueryClient } from '@tanstack/react-query'; @@ -95,9 +93,6 @@ export function ProjectSidebar({ const queryClient = useQueryClient(); const { data: projects = [], isLoading, error } = useProjects(); const [favorites] = useLocalStorage('project-favorites', []); - const projectsManager = useProjectsManager(); - const { toast } = useToast(); - const [isZipDialogOpen, setIsZipDialogOpen] = useState(false); const isMobile = useIsMobile(); const navigate = useNavigate(); @@ -123,24 +118,7 @@ export function ProjectSidebar({ } }; - const handleImportZip = async (file: File, overwrite = false, projectId?: string) => { - try { - // Import project from zip file - const project = await projectsManager.importProjectFromZip(file, projectId, overwrite); - // Show success toast - toast({ - title: overwrite ? "Project Overwritten Successfully" : "Project Imported Successfully", - description: `"${project.name}" has been ${overwrite ? 'overwritten' : 'imported'} and is ready to use.`, - }); - - // Navigate to the imported project - navigate(`/project/${project.id}`); - } catch (error) { - console.error('Failed to import project:', error); - throw error; // Re-throw to let the dialog handle the error display - } - }; useEffect(() => { queryClient.invalidateQueries({ queryKey: ['projects'] }); @@ -211,13 +189,6 @@ export function ProjectSidebar({ {t('importRepository')} - setIsZipDialogOpen(true)} - className="flex items-center gap-2 w-full" - > - - Import ZIP File - @@ -281,12 +252,7 @@ export function ProjectSidebar({ - {/* ZIP Import Dialog */} - + ); } \ No newline at end of file diff --git a/src/pages/Clone.tsx b/src/pages/Clone.tsx index 01ec43ca..ac4b54e6 100644 --- a/src/pages/Clone.tsx +++ b/src/pages/Clone.tsx @@ -4,11 +4,12 @@ import { useTranslation } from 'react-i18next'; import { AppLayout } from '@/components/AppLayout'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; -import { GitBranch, Loader2, AlertCircle } from 'lucide-react'; +import { GitBranch, Loader2, AlertCircle, FileArchive, MoreHorizontal } from 'lucide-react'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useToast } from '@/hooks/useToast'; - +import { ZipImportDialog } from '@/components/ZipImportDialog'; import { useSeoMeta } from '@unhead/react'; +import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '@/components/ui/dropdown-menu'; export default function Clone() { const { t } = useTranslation(); @@ -20,6 +21,7 @@ export default function Clone() { const projectsManager = useProjectsManager(); const { toast } = useToast(); const autoCloneInitiatedRef = useRef(false); + const [isZipDialogOpen, setIsZipDialogOpen] = useState(false); useSeoMeta({ title: `${t('importRepository')} - Shakespeare`, @@ -171,6 +173,25 @@ export default function Clone() { } }, [handleClone, searchParams]); + const handleImportZip = async (file: File, overwrite = false, projectId?: string) => { + try { + // Import project from zip file + const project = await projectsManager.importProjectFromZip(file, projectId, overwrite); + + // Show success toast + toast({ + title: overwrite ? "Project Overwritten Successfully" : "Project Imported Successfully", + description: `"${project.name}" has been ${overwrite ? 'overwritten' : 'imported'} and is ready to use.`, + }); + + // Navigate to the imported project + navigate(`/project/${project.id}`); + } catch (error) { + console.error('Failed to import project:', error); + throw error; // Re-throw to let the dialog handle the error display + } + }; + return (
@@ -226,7 +247,35 @@ export default function Clone() { )}
+ + {/* Import ZIP File Link */} +
+ + + + + + setIsZipDialogOpen(true)} + > + + Import ZIP File + + + +
+ + {/* ZIP Import Dialog */} +
); } \ No newline at end of file