fix
Browse filesFiles changed (2)
35 unmodified lines36373839404135 unmodified linesconst [isResizingSettings, setIsResizingSettings] = useState(false);const [isDesktop, setIsDesktop] = useState(false);// Clear cache on app startup to ensure fresh datauseEffect(() => {if (typeof window !== 'undefined') {35 unmodified lines363738394041424344454635 unmodified linesconst [isResizingSettings, setIsResizingSettings] = useState(false);const [isDesktop, setIsDesktop] = useState(false);// Debug: Log currentRepoId changesuseEffect(() => {console.log('[App] 🔵 currentRepoId changed to:', currentRepoId);}, [currentRepoId]);// Clear cache on app startup to ensure fresh datauseEffect(() => {if (typeof window !== 'undefined') {
245 unmodified lines2462472482492502512522532542552562572582592602612622632642658 unmodified lines27427527627727827952 unmodified lines3323333343353363373383393403413423433443453464 unmodified lines351352353354355356357358359360361362363364365366367368369370371372373374375376377378379245 unmodified linessetImportError('');try {// Extract space ID from URL for duplicationconst spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);if (spaceMatch) {// This is a HuggingFace Space - duplicate itconst fromSpaceId = spaceMatch[1];console.log('[Import] Duplicating space:', fromSpaceId);const duplicateResult = await apiClient.duplicateSpace(fromSpaceId);if (duplicateResult.success) {// Also load the code in the editorconst importResult = await apiClient.importProject(importUrl);if (importResult.status === 'success' && onImport && importResult.code) {// Pass the duplicated space URL so it's tracked for future deploymentsonImport(importResult.code, importResult.language || 'html', duplicateResult.space_url);8 unmodified lines}} else {// Not a Space URL - fall back to regular importconst result = await apiClient.importProject(importUrl);if (result.status === 'success') {52 unmodified linesreturn;}// Import code and trigger AI redesign (don't duplicate yet)if (onImport && onStart) {// First import the code (this will set currentRepoId in the parent)onImport(result.code, result.language || 'html', redesignUrl);// Send redesign prompt with code context// Pass the repoId directly to avoid React state timing issuessetTimeout(async () => {const redesignPrompt = `I have existing code in the editor that I imported from ${redesignUrl}. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.Current code:\`\`\`${result.language || 'html'}4 unmodified lines- Minimal, clean components- Mobile-first responsive design- Modern UI/UX best practices- Better visual hierarchy and spacing${createPR ? '\n\nNote: After generating the redesign, I will create a Pull Request on the original space.' : '\n\nNote: After generating the redesign, I can deploy to a new space or duplicate the original space.'}`;if (onStart) {// For redesign WITHOUT PR: Don't pass repo ID (will create new space)// For redesign WITH PR: We'll handle PR creation separatelyconsole.log('[Redesign] createPR:', createPR);console.log('[Redesign] Will pass repoId: undefined (let auto-deploy create new space)');onStart(redesignPrompt, result.language || 'html', selectedModel, undefined);}if (createPR) {console.log('[Redesign] Will create PR after code generation completes');} else {console.log('[Redesign] Code will be generated. User can deploy/duplicate after.');}}, 100);setShowRedesignDialog(false);setRedesignUrl('');} else {setRedesignError('Missing required callbacks. Please try again.');}} catch (error: any) {console.error('Redesign error:', error);245 unmodified lines2462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762778 unmodified lines28628728828929029129252 unmodified lines3453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763774 unmodified lines382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444245 unmodified linessetImportError('');try {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);8 unmodified lines}} else {// Not a Space URL - fall back to regular importconsole.log('[Import] ❌ Not a HF Space URL - using regular import');const result = await apiClient.importProject(importUrl);if (result.status === 'success') {52 unmodified linesreturn;}if (!createPR) {// Option 1: Redesign WITHOUT PR - Duplicate space first, then generate redesignconsole.log('[Redesign] Duplicating space first:', repoId);try {const duplicateResult = await apiClient.duplicateSpace(repoId);console.log('[Redesign] Duplicate result:', duplicateResult);if (!duplicateResult.success) {setRedesignError(duplicateResult.message || 'Failed to duplicate space');setIsRedesigning(false);return;}// Load code and trigger redesignif (onImport && onStart) {// Pass duplicated space URLonImport(result.code, result.language || 'html', duplicateResult.space_url);// Extract duplicated space ID to pass to generationconst dupSpaceMatch = duplicateResult.space_url?.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);const duplicatedRepoId = dupSpaceMatch ? dupSpaceMatch[1] : undefined;console.log('[Redesign] Duplicated space ID:', duplicatedRepoId);setTimeout(() => {const redesignPrompt = `I have existing code in the editor from a duplicated space. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.Current code:\`\`\`${result.language || 'html'}4 unmodified lines- Minimal, clean components- Mobile-first responsive design- Modern UI/UX best practices- Better visual hierarchy and spacing`;if (onStart) {// Pass duplicated space ID so auto-deploy updates itconsole.log('[Redesign] Calling onStart with duplicated repo ID:', duplicatedRepoId);onStart(redesignPrompt, result.language || 'html', selectedModel, duplicatedRepoId);}}, 100);// Show success messagealert(`✅ Space duplicated!\n\nYour space: ${duplicateResult.space_url}\n\nGenerating redesign now...`);}setShowRedesignDialog(false);setRedesignUrl('');} catch (dupError: any) {console.error('[Redesign] Duplication error:', dupError);setRedesignError(dupError.response?.data?.message || dupError.message || 'Failed to duplicate space');setIsRedesigning(false);return;}} else {// Option 2: Redesign WITH PR - Import code and generate, then create PRif (onImport && onStart) {onImport(result.code, result.language || 'html', redesignUrl);setTimeout(() => {const redesignPrompt = `I have existing code in the editor that I imported from ${redesignUrl}. Please redesign it to make it look better with minimal components needed, mobile friendly, and modern design.Current code:\`\`\`${result.language || 'html'}${result.code}\`\`\`Please redesign this with:- Minimal, clean components- Mobile-first responsive design- Modern UI/UX best practices- Better visual hierarchy and spacingNote: After generating the redesign, I will create a Pull Request on the original space.`;if (onStart) {console.log('[Redesign] Will create PR - not passing repo ID');onStart(redesignPrompt, result.language || 'html', selectedModel, undefined);}console.log('[Redesign] Will create PR after code generation completes');}, 100);setShowRedesignDialog(false);setRedesignUrl('');} else {setRedesignError('Missing required callbacks. Please try again.');}}} catch (error: any) {console.error('Redesign error:', error);
frontend/src/app/page.tsx+5
frontend/src/components/LandingPage.tsx+93-28