fix
Browse files
frontend/src/app/page.tsx
CHANGED
|
@@ -36,6 +36,11 @@ export default function Home() {
|
|
| 36 |
const [isResizingSettings, setIsResizingSettings] = useState(false);
|
| 37 |
const [isDesktop, setIsDesktop] = useState(false);
|
| 38 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 39 |
// Clear cache on app startup to ensure fresh data
|
| 40 |
useEffect(() => {
|
| 41 |
if (typeof window !== 'undefined') {
|
|
|
|
| 36 |
const [isResizingSettings, setIsResizingSettings] = useState(false);
|
| 37 |
const [isDesktop, setIsDesktop] = useState(false);
|
| 38 |
|
| 39 |
+
// Debug: Log currentRepoId changes
|
| 40 |
+
useEffect(() => {
|
| 41 |
+
console.log('[App] π΅ currentRepoId changed to:', currentRepoId);
|
| 42 |
+
}, [currentRepoId]);
|
| 43 |
+
|
| 44 |
// Clear cache on app startup to ensure fresh data
|
| 45 |
useEffect(() => {
|
| 46 |
if (typeof window !== 'undefined') {
|
frontend/src/components/LandingPage.tsx
CHANGED
|
@@ -246,20 +246,32 @@ export default function LandingPage({
|
|
| 246 |
setImportError('');
|
| 247 |
|
| 248 |
try {
|
|
|
|
|
|
|
|
|
|
| 249 |
// Extract space ID from URL for duplication
|
| 250 |
const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
|
|
|
|
| 251 |
|
| 252 |
if (spaceMatch) {
|
| 253 |
// This is a HuggingFace Space - duplicate it
|
| 254 |
const fromSpaceId = spaceMatch[1];
|
| 255 |
-
console.log('[Import]
|
|
|
|
| 256 |
|
| 257 |
const duplicateResult = await apiClient.duplicateSpace(fromSpaceId);
|
|
|
|
| 258 |
|
| 259 |
if (duplicateResult.success) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
// Also load the code in the editor
|
| 261 |
const importResult = await apiClient.importProject(importUrl);
|
| 262 |
if (importResult.status === 'success' && onImport && importResult.code) {
|
|
|
|
| 263 |
// Pass the duplicated space URL so it's tracked for future deployments
|
| 264 |
onImport(importResult.code, importResult.language || 'html', duplicateResult.space_url);
|
| 265 |
|
|
@@ -274,6 +286,7 @@ export default function LandingPage({
|
|
| 274 |
}
|
| 275 |
} else {
|
| 276 |
// Not a Space URL - fall back to regular import
|
|
|
|
| 277 |
const result = await apiClient.importProject(importUrl);
|
| 278 |
|
| 279 |
if (result.status === 'success') {
|
|
@@ -332,15 +345,33 @@ export default function LandingPage({
|
|
| 332 |
return;
|
| 333 |
}
|
| 334 |
|
| 335 |
-
|
| 336 |
-
|
| 337 |
-
|
| 338 |
-
onImport(result.code, result.language || 'html', redesignUrl);
|
| 339 |
|
| 340 |
-
|
| 341 |
-
|
| 342 |
-
|
| 343 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 344 |
|
| 345 |
Current code:
|
| 346 |
\`\`\`${result.language || 'html'}
|
|
@@ -351,29 +382,63 @@ Please redesign this with:
|
|
| 351 |
- Minimal, clean components
|
| 352 |
- Mobile-first responsive design
|
| 353 |
- Modern UI/UX best practices
|
| 354 |
-
- Better visual hierarchy and spacing
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
| 362 |
-
|
| 363 |
-
|
|
|
|
| 364 |
}
|
| 365 |
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
|
|
|
|
|
|
|
|
|
| 372 |
|
| 373 |
-
setShowRedesignDialog(false);
|
| 374 |
-
setRedesignUrl('');
|
| 375 |
} else {
|
| 376 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
}
|
| 378 |
} catch (error: any) {
|
| 379 |
console.error('Redesign error:', error);
|
|
|
|
| 246 |
setImportError('');
|
| 247 |
|
| 248 |
try {
|
| 249 |
+
console.log('[Import] ========== STARTING IMPORT ==========');
|
| 250 |
+
console.log('[Import] Import URL:', importUrl);
|
| 251 |
+
|
| 252 |
// Extract space ID from URL for duplication
|
| 253 |
const spaceMatch = importUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
|
| 254 |
+
console.log('[Import] Space regex match result:', spaceMatch);
|
| 255 |
|
| 256 |
if (spaceMatch) {
|
| 257 |
// This is a HuggingFace Space - duplicate it
|
| 258 |
const fromSpaceId = spaceMatch[1];
|
| 259 |
+
console.log('[Import] β
Detected HF Space - will duplicate:', fromSpaceId);
|
| 260 |
+
console.log('[Import] Calling apiClient.duplicateSpace...');
|
| 261 |
|
| 262 |
const duplicateResult = await apiClient.duplicateSpace(fromSpaceId);
|
| 263 |
+
console.log('[Import] Duplicate API response:', duplicateResult);
|
| 264 |
|
| 265 |
if (duplicateResult.success) {
|
| 266 |
+
console.log('[Import] ========== DUPLICATE SUCCESS ==========');
|
| 267 |
+
console.log('[Import] Duplicated space URL:', duplicateResult.space_url);
|
| 268 |
+
console.log('[Import] Duplicated space ID:', duplicateResult.space_id);
|
| 269 |
+
console.log('[Import] ==========================================');
|
| 270 |
+
|
| 271 |
// Also load the code in the editor
|
| 272 |
const importResult = await apiClient.importProject(importUrl);
|
| 273 |
if (importResult.status === 'success' && onImport && importResult.code) {
|
| 274 |
+
console.log('[Import] Calling onImport with duplicated space URL:', duplicateResult.space_url);
|
| 275 |
// Pass the duplicated space URL so it's tracked for future deployments
|
| 276 |
onImport(importResult.code, importResult.language || 'html', duplicateResult.space_url);
|
| 277 |
|
|
|
|
| 286 |
}
|
| 287 |
} else {
|
| 288 |
// Not a Space URL - fall back to regular import
|
| 289 |
+
console.log('[Import] β Not a HF Space URL - using regular import');
|
| 290 |
const result = await apiClient.importProject(importUrl);
|
| 291 |
|
| 292 |
if (result.status === 'success') {
|
|
|
|
| 345 |
return;
|
| 346 |
}
|
| 347 |
|
| 348 |
+
if (!createPR) {
|
| 349 |
+
// Option 1: Redesign WITHOUT PR - Duplicate space first, then generate redesign
|
| 350 |
+
console.log('[Redesign] Duplicating space first:', repoId);
|
|
|
|
| 351 |
|
| 352 |
+
try {
|
| 353 |
+
const duplicateResult = await apiClient.duplicateSpace(repoId);
|
| 354 |
+
console.log('[Redesign] Duplicate result:', duplicateResult);
|
| 355 |
+
|
| 356 |
+
if (!duplicateResult.success) {
|
| 357 |
+
setRedesignError(duplicateResult.message || 'Failed to duplicate space');
|
| 358 |
+
setIsRedesigning(false);
|
| 359 |
+
return;
|
| 360 |
+
}
|
| 361 |
+
|
| 362 |
+
// Load code and trigger redesign
|
| 363 |
+
if (onImport && onStart) {
|
| 364 |
+
// Pass duplicated space URL
|
| 365 |
+
onImport(result.code, result.language || 'html', duplicateResult.space_url);
|
| 366 |
+
|
| 367 |
+
// Extract duplicated space ID to pass to generation
|
| 368 |
+
const dupSpaceMatch = duplicateResult.space_url?.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
|
| 369 |
+
const duplicatedRepoId = dupSpaceMatch ? dupSpaceMatch[1] : undefined;
|
| 370 |
+
|
| 371 |
+
console.log('[Redesign] Duplicated space ID:', duplicatedRepoId);
|
| 372 |
+
|
| 373 |
+
setTimeout(() => {
|
| 374 |
+
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.
|
| 375 |
|
| 376 |
Current code:
|
| 377 |
\`\`\`${result.language || 'html'}
|
|
|
|
| 382 |
- Minimal, clean components
|
| 383 |
- Mobile-first responsive design
|
| 384 |
- Modern UI/UX best practices
|
| 385 |
+
- Better visual hierarchy and spacing`;
|
| 386 |
+
|
| 387 |
+
if (onStart) {
|
| 388 |
+
// Pass duplicated space ID so auto-deploy updates it
|
| 389 |
+
console.log('[Redesign] Calling onStart with duplicated repo ID:', duplicatedRepoId);
|
| 390 |
+
onStart(redesignPrompt, result.language || 'html', selectedModel, duplicatedRepoId);
|
| 391 |
+
}
|
| 392 |
+
}, 100);
|
| 393 |
+
|
| 394 |
+
// Show success message
|
| 395 |
+
alert(`β
Space duplicated!\n\nYour space: ${duplicateResult.space_url}\n\nGenerating redesign now...`);
|
| 396 |
}
|
| 397 |
|
| 398 |
+
setShowRedesignDialog(false);
|
| 399 |
+
setRedesignUrl('');
|
| 400 |
+
|
| 401 |
+
} catch (dupError: any) {
|
| 402 |
+
console.error('[Redesign] Duplication error:', dupError);
|
| 403 |
+
setRedesignError(dupError.response?.data?.message || dupError.message || 'Failed to duplicate space');
|
| 404 |
+
setIsRedesigning(false);
|
| 405 |
+
return;
|
| 406 |
+
}
|
| 407 |
|
|
|
|
|
|
|
| 408 |
} else {
|
| 409 |
+
// Option 2: Redesign WITH PR - Import code and generate, then create PR
|
| 410 |
+
if (onImport && onStart) {
|
| 411 |
+
onImport(result.code, result.language || 'html', redesignUrl);
|
| 412 |
+
|
| 413 |
+
setTimeout(() => {
|
| 414 |
+
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.
|
| 415 |
+
|
| 416 |
+
Current code:
|
| 417 |
+
\`\`\`${result.language || 'html'}
|
| 418 |
+
${result.code}
|
| 419 |
+
\`\`\`
|
| 420 |
+
|
| 421 |
+
Please redesign this with:
|
| 422 |
+
- Minimal, clean components
|
| 423 |
+
- Mobile-first responsive design
|
| 424 |
+
- Modern UI/UX best practices
|
| 425 |
+
- Better visual hierarchy and spacing
|
| 426 |
+
|
| 427 |
+
Note: After generating the redesign, I will create a Pull Request on the original space.`;
|
| 428 |
+
|
| 429 |
+
if (onStart) {
|
| 430 |
+
console.log('[Redesign] Will create PR - not passing repo ID');
|
| 431 |
+
onStart(redesignPrompt, result.language || 'html', selectedModel, undefined);
|
| 432 |
+
}
|
| 433 |
+
|
| 434 |
+
console.log('[Redesign] Will create PR after code generation completes');
|
| 435 |
+
}, 100);
|
| 436 |
+
|
| 437 |
+
setShowRedesignDialog(false);
|
| 438 |
+
setRedesignUrl('');
|
| 439 |
+
} else {
|
| 440 |
+
setRedesignError('Missing required callbacks. Please try again.');
|
| 441 |
+
}
|
| 442 |
}
|
| 443 |
} catch (error: any) {
|
| 444 |
console.error('Redesign error:', error);
|