akhaliq HF Staff commited on
Commit
e2918f7
Β·
1 Parent(s): 8f21cf3
frontend/src/app/page.tsx CHANGED
@@ -232,7 +232,7 @@ export default function Home() {
232
  }
233
  };
234
 
235
- const handleSendMessage = async (message: string, overrideLanguage?: Language, overrideModel?: string) => {
236
  if (!isAuthenticated) {
237
  alert('Please sign in with HuggingFace first! Click the "Sign in with Hugging Face" button in the header.');
238
  return;
@@ -278,6 +278,15 @@ export default function Home() {
278
  setGeneratedCode('');
279
 
280
  // Prepare request with enhanced query that includes current code
 
 
 
 
 
 
 
 
 
281
  const request: CodeGenerationRequest = {
282
  query: enhancedMessage,
283
  language: language,
@@ -285,7 +294,7 @@ export default function Home() {
285
  provider: 'auto',
286
  history: messages.map((m) => [m.role, m.content]),
287
  agent_mode: false,
288
- existing_repo_id: currentRepoId || undefined, // Pass duplicated/imported space ID for auto-deploy
289
  };
290
 
291
  const assistantMessage: Message = {
@@ -655,8 +664,10 @@ export default function Home() {
655
 
656
  // Only set as current repo if user owns it
657
  if (username && importedRepoId.startsWith(`${username}/`)) {
 
658
  setCurrentRepoId(importedRepoId);
659
- console.log('[Import] βœ…βœ…βœ… SETTING currentRepoId to:', importedRepoId);
 
660
  } else {
661
  // User doesn't own the imported space, clear current repo
662
  setCurrentRepoId(null);
@@ -697,11 +708,12 @@ export default function Home() {
697
  };
698
 
699
  // Handle landing page prompt submission
700
- const handleLandingPageStart = async (prompt: string, language: Language, modelId: string) => {
701
  // Hide landing page immediately for smooth transition
702
  setShowLandingPage(false);
703
  // Send the message with the selected language and model
704
- await handleSendMessage(prompt, language, modelId);
 
705
  };
706
 
707
  // Resize handlers for chat sidebar (desktop only)
 
232
  }
233
  };
234
 
235
+ const handleSendMessage = async (message: string, overrideLanguage?: Language, overrideModel?: string, overrideRepoId?: string) => {
236
  if (!isAuthenticated) {
237
  alert('Please sign in with HuggingFace first! Click the "Sign in with Hugging Face" button in the header.');
238
  return;
 
278
  setGeneratedCode('');
279
 
280
  // Prepare request with enhanced query that includes current code
281
+ // Use overrideRepoId if provided (from import/duplicate), otherwise use currentRepoId from state
282
+ const effectiveRepoId = overrideRepoId || currentRepoId || undefined;
283
+
284
+ console.log('[SendMessage] ========== GENERATION REQUEST ==========');
285
+ console.log('[SendMessage] overrideRepoId:', overrideRepoId);
286
+ console.log('[SendMessage] currentRepoId:', currentRepoId);
287
+ console.log('[SendMessage] effectiveRepoId (will use):', effectiveRepoId);
288
+ console.log('[SendMessage] ==========================================');
289
+
290
  const request: CodeGenerationRequest = {
291
  query: enhancedMessage,
292
  language: language,
 
294
  provider: 'auto',
295
  history: messages.map((m) => [m.role, m.content]),
296
  agent_mode: false,
297
+ existing_repo_id: effectiveRepoId, // Pass duplicated/imported space ID for auto-deploy
298
  };
299
 
300
  const assistantMessage: Message = {
 
664
 
665
  // Only set as current repo if user owns it
666
  if (username && importedRepoId.startsWith(`${username}/`)) {
667
+ console.log('[Import] βœ…βœ…βœ… BEFORE setCurrentRepoId - currentRepoId was:', currentRepoId);
668
  setCurrentRepoId(importedRepoId);
669
+ console.log('[Import] βœ…βœ…βœ… CALLED setCurrentRepoId with:', importedRepoId);
670
+ console.log('[Import] βœ…βœ…βœ… Note: State update is async, currentRepoId will update later');
671
  } else {
672
  // User doesn't own the imported space, clear current repo
673
  setCurrentRepoId(null);
 
708
  };
709
 
710
  // Handle landing page prompt submission
711
+ const handleLandingPageStart = async (prompt: string, language: Language, modelId: string, repoId?: string) => {
712
  // Hide landing page immediately for smooth transition
713
  setShowLandingPage(false);
714
  // Send the message with the selected language and model
715
+ // Pass repoId if provided (for imported/duplicated spaces)
716
+ await handleSendMessage(prompt, language, modelId, repoId);
717
  };
718
 
719
  // Resize handlers for chat sidebar (desktop only)
frontend/src/components/LandingPage.tsx CHANGED
@@ -15,7 +15,7 @@ import type { Model, Language } from '@/types';
15
  import type { OAuthUserInfo } from '@/lib/auth';
16
 
17
  interface LandingPageProps {
18
- onStart: (prompt: string, language: Language, modelId: string) => void;
19
  onImport?: (code: string, language: Language, importUrl?: string) => void;
20
  isAuthenticated: boolean;
21
  initialLanguage?: Language;
@@ -334,9 +334,11 @@ export default function LandingPage({
334
 
335
  // Import code and trigger AI redesign (don't duplicate yet)
336
  if (onImport && onStart) {
 
337
  onImport(result.code, result.language || 'html', redesignUrl);
338
 
339
  // Send redesign prompt with code context
 
340
  setTimeout(async () => {
341
  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.
342
 
@@ -354,7 +356,11 @@ Please redesign this with:
354
  ${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.'}`;
355
 
356
  if (onStart) {
357
- onStart(redesignPrompt, result.language || 'html', selectedModel);
 
 
 
 
358
  }
359
 
360
  if (createPR) {
 
15
  import type { OAuthUserInfo } from '@/lib/auth';
16
 
17
  interface LandingPageProps {
18
+ onStart: (prompt: string, language: Language, modelId: string, repoId?: string) => void;
19
  onImport?: (code: string, language: Language, importUrl?: string) => void;
20
  isAuthenticated: boolean;
21
  initialLanguage?: Language;
 
334
 
335
  // Import code and trigger AI redesign (don't duplicate yet)
336
  if (onImport && onStart) {
337
+ // First import the code (this will set currentRepoId in the parent)
338
  onImport(result.code, result.language || 'html', redesignUrl);
339
 
340
  // Send redesign prompt with code context
341
+ // Pass the repoId directly to avoid React state timing issues
342
  setTimeout(async () => {
343
  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.
344
 
 
356
  ${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.'}`;
357
 
358
  if (onStart) {
359
+ // Extract repo ID from URL to pass directly (avoids state timing issues)
360
+ const spaceMatch = redesignUrl.match(/huggingface\.co\/spaces\/([^\/\s\)]+\/[^\/\s\)]+)/);
361
+ const extractedRepoId = spaceMatch ? spaceMatch[1] : undefined;
362
+ console.log('[Redesign] Passing repoId to onStart:', extractedRepoId);
363
+ onStart(redesignPrompt, result.language || 'html', selectedModel, extractedRepoId);
364
  }
365
 
366
  if (createPR) {