+ {headerContent}
+
+
+ {/* Mobile Sidebar Overlay - only show if user has local projects and showSidebar is true */}
+ {showSidebar && projects.length > 0 && isSidebarVisible && (
+
+ {/* Backdrop - only covers the area not occupied by the sidebar */}
+
+ {
+ setIsSidebarVisible(false); // Always collapse sidebar on mobile navigation
+ handleProjectSelect(project);
+ }}
+ />
+
+
+ )}
+
+
+ {children}
+
+
+ );
+ }
+
+ return (
+
+ {/* Fixed Sidebar - only show if user has created local projects and showSidebar is true */}
+ {showSidebar && projects.length > 0 && (
+
+
+
+ )}
+
+ {/* Main Content Area */}
+
+
+ {/* Header - only show toggle button if user has local projects and showSidebar is true */}
+ {!isSidebarVisible && showSidebar && projects.length > 0 && (
+
+
+
+ {title}
+
+
+ {headerContent}
+
+
+ )}
+
+
+ {children}
+
+
+
+
+ );
+}
\ No newline at end of file
diff --git a/src/components/ProjectSidebar.tsx b/src/components/ProjectSidebar.tsx
index e9cbff58..501de731 100644
--- a/src/components/ProjectSidebar.tsx
+++ b/src/components/ProjectSidebar.tsx
@@ -1,6 +1,6 @@
import React, { useState } from 'react';
import { useNavigate } from 'react-router-dom';
-import { Plus, Loader2, Info, MoreVertical, Trash2, Eye, Star, Bug, Folder, Download } from 'lucide-react';
+import { Plus, Loader2, Info, MoreVertical, Trash2, Eye, Star, Bug, Folder, Download, GitBranch } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Skeleton } from '@/components/ui/skeleton';
import { Label } from '@/components/ui/label';
@@ -309,6 +309,13 @@ export function ProjectSidebar({
+ navigate('/clone')}
+ className="flex items-center gap-2 w-full"
+ >
+
+ Import Repository
+ {
+ return this.cloneProject(name, GIT_TEMPLATE_URL);
+ }
+
+ async cloneProject(name: string, repoUrl: string): Promise {
const id = await this.generateUniqueProjectId(name);
const projectPath = `${this.dir}/${id}`;
await this.fs.mkdir(projectPath);
- // Clone the template first
- await this.cloneTemplate(projectPath);
+ // Clone the repository
+ await git.clone({
+ fs: this.fs,
+ http,
+ dir: projectPath,
+ url: repoUrl,
+ singleBranch: true,
+ depth: 1,
+ });
// Get filesystem stats for timestamps
const stats = await this.fs.stat(projectPath);
@@ -57,16 +68,7 @@ export class ProjectsManager {
};
}
- async cloneTemplate(projectPath: string) {
- await git.clone({
- fs: this.fs,
- http,
- dir: projectPath,
- url: GIT_TEMPLATE_URL,
- singleBranch: true,
- depth: 1,
- });
- }
+
async getProjects(): Promise {
try {
@@ -187,27 +189,20 @@ export class ProjectsManager {
}
private async deleteDirectory(dirPath: string): Promise {
- try {
- const files = await this.fs.readdir(dirPath);
+ const files = await this.fs.readdir(dirPath);
- for (const file of files) {
- const fullPath = `${dirPath}/${file}`;
- const stat = await this.fs.stat(fullPath);
+ for (const file of files) {
+ const fullPath = `${dirPath}/${file}`;
+ const stat = await this.fs.lstat(fullPath);
- if (stat.isDirectory()) {
- await this.deleteDirectory(fullPath);
- } else {
- await this.fs.unlink(fullPath);
- }
- }
-
- await this.fs.rmdir(dirPath);
- } catch (error) {
- const fsError = error as NodeJS.ErrnoException;
- if (fsError.code !== 'ENOENT') {
- throw error;
+ if (stat.isDirectory()) {
+ await this.deleteDirectory(fullPath);
+ } else {
+ await this.fs.unlink(fullPath);
}
}
+
+ await this.fs.rmdir(dirPath);
}
private async generateUniqueProjectId(name: string): Promise {
diff --git a/src/pages/Clone.tsx b/src/pages/Clone.tsx
new file mode 100644
index 00000000..51184b41
--- /dev/null
+++ b/src/pages/Clone.tsx
@@ -0,0 +1,210 @@
+import { useState } from 'react';
+import { useNavigate } from 'react-router-dom';
+import { AppLayout } from '@/components/AppLayout';
+import { Button } from '@/components/ui/button';
+import { Input } from '@/components/ui/input';
+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
+import { Label } from '@/components/ui/label';
+import { GitBranch, Loader2, AlertCircle } from 'lucide-react';
+import { useProjectsManager } from '@/hooks/useProjectsManager';
+import { useToast } from '@/hooks/useToast';
+
+import { useSeoMeta } from '@unhead/react';
+
+export default function Clone() {
+ const [repoUrl, setRepoUrl] = useState('');
+ const [isCloning, setIsCloning] = useState(false);
+ const [error, setError] = useState(null);
+ const navigate = useNavigate();
+ const projectsManager = useProjectsManager();
+ const { toast } = useToast();
+
+ useSeoMeta({
+ title: 'Import Repository - Shakespeare',
+ description: 'Import a Git repository into your Shakespeare workspace',
+ });
+
+ const extractRepoName = (url: string): string => {
+ try {
+ // Handle different URL formats
+ const cleanUrl = url.trim();
+
+ // Extract from GitHub URLs, GitLab URLs, etc.
+ const match = cleanUrl.match(/\/([^/]+?)(?:\.git)?(?:\/)?$/);
+ if (match && match[1]) {
+ return match[1];
+ }
+
+ // Fallback: use the last part of the URL
+ const parts = cleanUrl.split('/').filter(Boolean);
+ const lastPart = parts[parts.length - 1];
+ return lastPart.replace('.git', '') || 'imported-repo';
+ } catch {
+ return 'imported-repo';
+ }
+ };
+
+ const validateGitUrl = (url: string): boolean => {
+ if (!url.trim()) return false;
+
+ // Basic URL validation
+ try {
+ new URL(url);
+ } catch {
+ return false;
+ }
+
+ // Check if it looks like a git repository URL
+ const gitUrlPattern = /^https?:\/\/.*\.git$|^https?:\/\/github\.com\/.*\/.*$|^https?:\/\/gitlab\.com\/.*\/.*$/i;
+ return gitUrlPattern.test(url) || url.includes('github.com') || url.includes('gitlab.com');
+ };
+
+ const handleClone = async () => {
+ if (!repoUrl.trim()) {
+ setError('Please enter a repository URL');
+ return;
+ }
+
+ if (!validateGitUrl(repoUrl)) {
+ setError('Please enter a valid Git repository URL (e.g., https://github.com/user/repo.git)');
+ return;
+ }
+
+ setIsCloning(true);
+ setError(null);
+
+ try {
+ // Extract repository name from URL
+ const repoName = extractRepoName(repoUrl);
+
+ // Clone the repository using ProjectsManager
+ await projectsManager.init();
+ const project = await projectsManager.cloneProject(repoName, repoUrl.trim());
+
+ toast({
+ title: "Repository imported successfully",
+ description: `"${repoName}" has been cloned and is ready for development.`,
+ });
+
+ // Navigate to the new project
+ navigate(`/project/${project.id}`);
+ } catch (error) {
+ console.error('Failed to clone repository:', error);
+
+ let errorMessage = 'Failed to clone repository';
+ if (error instanceof Error) {
+ if (error.message.includes('404') || error.message.includes('not found')) {
+ errorMessage = 'Repository not found. Please check the URL and try again.';
+ } else if (error.message.includes('403') || error.message.includes('forbidden')) {
+ errorMessage = 'Access denied. The repository may be private or require authentication.';
+ } else if (error.message.includes('network') || error.message.includes('fetch')) {
+ errorMessage = 'Network error. Please check your connection and try again.';
+ } else {
+ errorMessage = error.message;
+ }
+ }
+
+ setError(errorMessage);
+
+ toast({
+ title: "Failed to import repository",
+ description: errorMessage,
+ variant: "destructive",
+ });
+ } finally {
+ setIsCloning(false);
+ }
+ };
+
+ const handleKeyDown = (e: React.KeyboardEvent) => {
+ if (e.key === 'Enter' && !isCloning) {
+ handleClone();
+ }
+ };
+
+ return (
+
+
+
+
+
+
+
+ Import Repository
+
+
+ Clone a Git repository into your Shakespeare workspace
+
+
+
+
+
+ Repository URL
+
+ Enter the HTTPS URL of the Git repository you want to import
+
+
+
+