import React, { useState } from 'react'; import { Project } from '../types'; import { downloadSingleFile } from '../utils/exportZip'; import { FileCode, FileText, Plus, Trash2, Download, Copy, Check, FolderTree, } from 'lucide-react'; interface CodeWorkspaceProps { project: Project; onUpdateFileContent: (fileId: string, newContent: string) => void; onAddFile: (name: string, content?: string) => void; onDeleteFile: (fileId: string) => void; } export const CodeWorkspace: React.FC = ({ project, onUpdateFileContent, onAddFile, onDeleteFile, }) => { const [activeFileId, setActiveFileId] = useState( project.activeFileId || project.files[0]?.id || '' ); const [copied, setCopied] = useState(false); const [newFileName, setNewFileName] = useState(''); const [isAddingFile, setIsAddingFile] = useState(false); const activeFile = project.files.find((f) => f.id === activeFileId) || project.files[0]; const handleCopy = () => { if (!activeFile) return; navigator.clipboard.writeText(activeFile.content); setCopied(true); setTimeout(() => setCopied(false), 2000); }; const handleCreateFile = (e: React.FormEvent) => { e.preventDefault(); if (!newFileName.trim()) return; onAddFile(newFileName.trim(), '// New file created in RiShre\n'); setNewFileName(''); setIsAddingFile(false); }; const lineCount = activeFile?.content ? activeFile.content.split('\n').length : 0; const lineNumbers = Array.from({ length: Math.max(lineCount, 1) }, (_, i) => i + 1); return (
{/* File Explorer Sidebar */}
PROJECT FILES
{/* Add File Inline Input */} {isAddingFile && (
setNewFileName(e.target.value)} className="w-full bg-[#080314] border border-purple-500/50 rounded-lg px-2.5 py-1 text-xs text-white focus:outline-none" />
)} {/* File Tree List */}
{project.files.map((file) => { const isActive = file.id === activeFile?.id; return (
setActiveFileId(file.id)} className={`group flex items-center justify-between px-2.5 py-1.5 rounded-xl text-xs font-mono transition-colors cursor-pointer ${ isActive ? 'bg-purple-600/20 text-purple-100 font-bold border border-purple-500/40 shadow-[0_0_12px_rgba(168,85,247,0.2)]' : 'text-purple-300/70 hover:text-purple-100 hover:bg-[#130829]' }`} >
{file.name}
{project.files.length > 1 && ( )}
); })}
{/* Code Editor Area */}
{activeFile ? ( <> {/* Tab & Editor Actions Header */}
{activeFile.name} {activeFile.language} {lineCount} lines
{/* Editor Body with Gutter */}
{lineNumbers.map((num) => (
{num}
))}