update
Browse filesFiles changed (2)
868 unmodified lines869870871872873874868 unmodified linesinitialLanguage={selectedLanguage}initialModel={selectedModel}onAuthChange={checkAuth}/></div>);868 unmodified lines869870871872873874875876868 unmodified linesinitialLanguage={selectedLanguage}initialModel={selectedModel}onAuthChange={checkAuth}setPendingPR={setPendingPR}pendingPRRef={pendingPRRef}/></div>);
20 unmodified lines2122232425262 unmodified lines2930313233343526 unmodified lines626364656667163 unmodified lines23123223323423523611 unmodified lines248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288437 unmodified lines7267277287297307317327337347357367377387397407 unmodified lines74874975075175275320 unmodified linesinitialLanguage?: Language;initialModel?: string;onAuthChange?: () => void;}export default function LandingPage({2 unmodified linesisAuthenticated,initialLanguage = 'html',initialModel = 'deepseek-ai/DeepSeek-V3.2-Exp',onAuthChange}: LandingPageProps) {const [prompt, setPrompt] = useState('');const [selectedLanguage, setSelectedLanguage] = useState<Language>(initialLanguage);26 unmodified linesconst [importUrl, setImportUrl] = useState('');const [isImporting, setIsImporting] = useState(false);const [importError, setImportError] = useState('');// Redesign project stateconst [redesignUrl, setRedesignUrl] = useState('');163 unmodified linesreturn lang.charAt(0).toUpperCase() + lang.slice(1);};const handleImportProject = async () => {if (!importUrl.trim()) {setImportError('Please enter a valid URL');11 unmodified linestry {console.log('[Import] ========== STARTING IMPORT ==========');console.log('[Import] Import URL:', importUrl);// Extract space ID from URL for duplicationconst spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);console.log('[Import] Space regex match result:', spaceMatch);if (spaceMatch) {// This is a HuggingFace Space - duplicate itconst fromSpaceId = spaceMatch[1];console.log('[Import] ✅ Detected HF Space - will duplicate:', fromSpaceId);console.log('[Import] Calling apiClient.duplicateSpace...');const duplicateResult = await apiClient.duplicateSpace(fromSpaceId);console.log('[Import] Duplicate API response:', duplicateResult);if (duplicateResult.success) {console.log('[Import] ========== DUPLICATE SUCCESS ==========');console.log('[Import] Duplicated space URL:', duplicateResult.space_url);console.log('[Import] Duplicated space ID:', duplicateResult.space_id);console.log('[Import] ==========================================');// Also load the code in the editorconst importResult = await apiClient.importProject(importUrl);if (importResult.status === 'success' && onImport && importResult.code) {console.log('[Import] Calling onImport with duplicated space URL:', duplicateResult.space_url);// Pass the duplicated space URL so it's tracked for future deploymentsonImport(importResult.code, importResult.language || 'html', duplicateResult.space_url);// Show success message with link to duplicated spacealert(`✅ Space duplicated successfully!\n\nYour space: ${duplicateResult.space_url}\n\nThe code has been loaded in the editor. Any changes you deploy will update this duplicated space.`);}setShowImportDialog(false);setImportUrl('');} else {setImportError(duplicateResult.message || 'Failed to duplicate space');}} else {// Not a Space URL - fall back to regular import437 unmodified lines<inputtype="text"value={importUrl}onChange={(e) => setImportUrl(e.target.value)}onKeyPress={(e) => e.key === 'Enter' && handleImportProject()}placeholder="https://huggingface.co/spaces/..."className="w-full px-3 py-2 rounded-lg text-xs bg-[#2d2d30] text-[#f5f5f7] border border-[#424245] focus:outline-none focus:border-white/50 font-normal mb-2"disabled={isImporting}/>{importError && (<p className="text-xs text-red-400 mb-2">{importError}</p>)}<div className="flex gap-2"><buttononClick={handleImportProject}7 unmodified linessetShowImportDialog(false);setImportUrl('');setImportError('');}}className="px-3 py-2 bg-[#2d2d30] text-[#f5f5f7] rounded-lg text-xs hover:bg-[#3d3d3f] font-medium">20 unmodified lines21222324252627282 unmodified lines31323334353637383926 unmodified lines6667686970717273163 unmodified lines23723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626711 unmodified lines279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368437 unmodified lines8068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908917 unmodified lines89990090190290390490590620 unmodified linesinitialLanguage?: Language;initialModel?: string;onAuthChange?: () => void;setPendingPR?: (pr: { repoId: string; language: Language } | null) => void;pendingPRRef?: React.MutableRefObject<{ repoId: string; language: Language } | null>;}export default function LandingPage({2 unmodified linesisAuthenticated,initialLanguage = 'html',initialModel = 'deepseek-ai/DeepSeek-V3.2-Exp',onAuthChange,setPendingPR,pendingPRRef}: LandingPageProps) {const [prompt, setPrompt] = useState('');const [selectedLanguage, setSelectedLanguage] = useState<Language>(initialLanguage);26 unmodified linesconst [importUrl, setImportUrl] = useState('');const [isImporting, setIsImporting] = useState(false);const [importError, setImportError] = useState('');const [importAction, setImportAction] = useState<'duplicate' | 'update' | 'pr'>('duplicate'); // Default to duplicateconst [isSpaceOwner, setIsSpaceOwner] = useState(false); // Track if user owns the space// Redesign project stateconst [redesignUrl, setRedesignUrl] = useState('');163 unmodified linesreturn lang.charAt(0).toUpperCase() + lang.slice(1);};// Check if user owns the imported spaceconst checkSpaceOwnership = (url: string) => {if (!url || !userInfo?.preferred_username) {setIsSpaceOwner(false);return;}const spaceMatch = url.match(/huggingface\.co\/spaces\/([^\/\s\)]+)\/[^\/\s\)]+/);if (spaceMatch) {const spaceOwner = spaceMatch[1];const isOwner = spaceOwner === userInfo.preferred_username;setIsSpaceOwner(isOwner);console.log('[Import] Space owner:', spaceOwner, '| Current user:', userInfo.preferred_username, '| Is owner:', isOwner);// Auto-select update mode if owner, otherwise duplicateif (isOwner) {setImportAction('update');} else {setImportAction('duplicate');}} else {setIsSpaceOwner(false);}};const handleImportProject = async () => {if (!importUrl.trim()) {setImportError('Please enter a valid URL');11 unmodified linestry {console.log('[Import] ========== STARTING IMPORT ==========');console.log('[Import] Import URL:', importUrl);console.log('[Import] Action:', importAction);// Extract space ID from URLconst spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);console.log('[Import] Space regex match result:', spaceMatch);if (spaceMatch) {const fromSpaceId = spaceMatch[1];console.log('[Import] ✅ Detected HF Space:', fromSpaceId);// Import the code first (always needed to load in editor)const importResult = await apiClient.importProject(importUrl);if (importResult.status !== 'success') {setImportError(importResult.message || 'Failed to import project');setIsImporting(false);return;}// Handle different import actionsif (importAction === 'update' && isSpaceOwner) {// Option 1: Update existing space directly (for owners)console.log('[Import] Owner update - loading code for direct update to:', fromSpaceId);if (onImport && importResult.code) {// Pass the original space URL so future deployments update itonImport(importResult.code, importResult.language || 'html', importUrl);alert(`✅ Code loaded!\n\nYou can now make changes and deploy them directly to: ${importUrl}\n\nThe code has been loaded in the editor.`);}setShowImportDialog(false);setImportUrl('');} else if (importAction === 'pr') {// Option 2: Create Pull Requestconsole.log('[Import] PR mode - loading code to create PR to:', fromSpaceId);if (onImport && importResult.code) {// Load code in editor with the original space for PR trackingonImport(importResult.code, importResult.language || 'html', importUrl);// Set pending PR state so any future code generation creates a PRif (setPendingPR && pendingPRRef) {const prInfo = { repoId: fromSpaceId, language: (importResult.language || 'html') as Language };setPendingPR(prInfo);pendingPRRef.current = prInfo;console.log('[Import PR] Set pending PR:', prInfo);}// Show success messagealert(`✅ Code loaded in PR mode!\n\nYou can now:\n• Make manual edits in the editor\n• Generate new features with AI\n\nWhen you deploy, a Pull Request will be created to: ${fromSpaceId}`);}setShowImportDialog(false);setImportUrl('');} else {// Option 3: Duplicate space (default)console.log('[Import] Duplicate mode - will duplicate:', fromSpaceId);const duplicateResult = await apiClient.duplicateSpace(fromSpaceId);console.log('[Import] Duplicate API response:', duplicateResult);if (duplicateResult.success) {console.log('[Import] ========== DUPLICATE SUCCESS ==========');console.log('[Import] Duplicated space URL:', duplicateResult.space_url);console.log('[Import] Duplicated space ID:', duplicateResult.space_id);console.log('[Import] ==========================================');if (onImport && importResult.code) {console.log('[Import] Calling onImport with duplicated space URL:', duplicateResult.space_url);// Pass the duplicated space URL so it's tracked for future deploymentsonImport(importResult.code, importResult.language || 'html', duplicateResult.space_url);// Show success message with link to duplicated spacealert(`✅ Space duplicated successfully!\n\nYour space: ${duplicateResult.space_url}\n\nThe code has been loaded in the editor. Any changes you deploy will update this duplicated space.`);}setShowImportDialog(false);setImportUrl('');} else {setImportError(duplicateResult.message || 'Failed to duplicate space');}}} else {// Not a Space URL - fall back to regular import437 unmodified lines<inputtype="text"value={importUrl}onChange={(e) => {setImportUrl(e.target.value);checkSpaceOwnership(e.target.value);}}onKeyPress={(e) => e.key === 'Enter' && handleImportProject()}placeholder="https://huggingface.co/spaces/..."className="w-full px-3 py-2 rounded-lg text-xs bg-[#2d2d30] text-[#f5f5f7] border border-[#424245] focus:outline-none focus:border-white/50 font-normal mb-3"disabled={isImporting}/>{/* Import Action Options */}{importUrl.includes('huggingface.co/spaces/') && (<div className="mb-3 space-y-2"><p className="text-[10px] font-medium text-[#86868b] mb-2">Import Mode:</p>{/* Update Space (only for owners) */}{isSpaceOwner && (<label className="flex items-start gap-2 cursor-pointer group"><inputtype="radio"checked={importAction === 'update'}onChange={() => setImportAction('update')}className="mt-0.5 w-3.5 h-3.5 rounded-full border-[#424245] bg-[#2d2d30] checked:bg-white checked:border-white"disabled={isImporting}/><div><span className="text-[11px] text-[#f5f5f7] font-medium">Update your space directly</span><p className="text-[10px] text-[#86868b] mt-0.5">✅ You own this space - changes will update it</p></div></label>)}{/* Duplicate Space */}<label className="flex items-start gap-2 cursor-pointer group"><inputtype="radio"checked={importAction === 'duplicate'}onChange={() => setImportAction('duplicate')}className="mt-0.5 w-3.5 h-3.5 rounded-full border-[#424245] bg-[#2d2d30] checked:bg-white checked:border-white"disabled={isImporting}/><div><span className="text-[11px] text-[#f5f5f7] font-medium">Duplicate to your account</span><p className="text-[10px] text-[#86868b] mt-0.5">Create a copy you can freely modify</p></div></label>{/* Create PR */}<label className="flex items-start gap-2 cursor-pointer group"><inputtype="radio"checked={importAction === 'pr'}onChange={() => setImportAction('pr')}className="mt-0.5 w-3.5 h-3.5 rounded-full border-[#424245] bg-[#2d2d30] checked:bg-white checked:border-white"disabled={isImporting}/><div><span className="text-[11px] text-[#f5f5f7] font-medium">Create Pull Request</span><p className="text-[10px] text-[#86868b] mt-0.5">Propose changes to the original space</p></div></label>{importAction === 'pr' && (<p className="text-[10px] text-[#86868b] ml-6 mt-1">⚠️ Requires space owner to enable PRs</p>)}</div>)}{importError && (<p className="text-xs text-red-400 mb-2">{importError}</p>)}<div className="flex gap-2"><buttononClick={handleImportProject}7 unmodified linessetShowImportDialog(false);setImportUrl('');setImportError('');setIsSpaceOwner(false);setImportAction('duplicate');}}className="px-3 py-2 bg-[#2d2d30] text-[#f5f5f7] rounded-lg text-xs hover:bg-[#3d3d3f] font-medium">
frontend/src/app/page.tsx+2
frontend/src/components/LandingPage.tsx+176-23