Spaces:
Running
Running
updates
Browse files
frontend/src/app/page.tsx
CHANGED
|
@@ -695,7 +695,7 @@ export default function Home() {
|
|
| 695 |
};
|
| 696 |
|
| 697 |
const handleClear = () => {
|
| 698 |
-
if (confirm('
|
| 699 |
setMessages([]);
|
| 700 |
setGeneratedCode('');
|
| 701 |
setShowLandingPage(true);
|
|
@@ -985,7 +985,6 @@ export default function Home() {
|
|
| 985 |
onLanguageChange={setSelectedLanguage}
|
| 986 |
onModelChange={setSelectedModel}
|
| 987 |
onClear={handleClear}
|
| 988 |
-
onImport={handleImport}
|
| 989 |
isGenerating={isGenerating}
|
| 990 |
/>
|
| 991 |
</div>
|
|
|
|
| 695 |
};
|
| 696 |
|
| 697 |
const handleClear = () => {
|
| 698 |
+
if (confirm('Start a new chat? This will clear all messages and code.')) {
|
| 699 |
setMessages([]);
|
| 700 |
setGeneratedCode('');
|
| 701 |
setShowLandingPage(true);
|
|
|
|
| 985 |
onLanguageChange={setSelectedLanguage}
|
| 986 |
onModelChange={setSelectedModel}
|
| 987 |
onClear={handleClear}
|
|
|
|
| 988 |
isGenerating={isGenerating}
|
| 989 |
/>
|
| 990 |
</div>
|
frontend/src/components/ControlPanel.tsx
CHANGED
|
@@ -10,7 +10,6 @@ interface ControlPanelProps {
|
|
| 10 |
onLanguageChange: (language: Language) => void;
|
| 11 |
onModelChange: (modelId: string) => void;
|
| 12 |
onClear: () => void;
|
| 13 |
-
onImport?: (code: string, language: Language, importUrl?: string) => void;
|
| 14 |
isGenerating: boolean;
|
| 15 |
}
|
| 16 |
|
|
@@ -20,16 +19,11 @@ export default function ControlPanel({
|
|
| 20 |
onLanguageChange,
|
| 21 |
onModelChange,
|
| 22 |
onClear,
|
| 23 |
-
onImport,
|
| 24 |
isGenerating,
|
| 25 |
}: ControlPanelProps) {
|
| 26 |
const [models, setModels] = useState<Model[]>([]);
|
| 27 |
const [languages, setLanguages] = useState<Language[]>([]);
|
| 28 |
const [isLoading, setIsLoading] = useState(true);
|
| 29 |
-
const [showImportModal, setShowImportModal] = useState(false);
|
| 30 |
-
const [importUrl, setImportUrl] = useState('');
|
| 31 |
-
const [isImporting, setIsImporting] = useState(false);
|
| 32 |
-
const [importError, setImportError] = useState<string | null>(null);
|
| 33 |
|
| 34 |
// Dropdown states
|
| 35 |
const [showLanguageDropdown, setShowLanguageDropdown] = useState(false);
|
|
@@ -86,42 +80,6 @@ export default function ControlPanel({
|
|
| 86 |
}
|
| 87 |
};
|
| 88 |
|
| 89 |
-
const handleImport = async () => {
|
| 90 |
-
if (!importUrl.trim()) {
|
| 91 |
-
setImportError('Please enter a valid URL');
|
| 92 |
-
return;
|
| 93 |
-
}
|
| 94 |
-
|
| 95 |
-
setIsImporting(true);
|
| 96 |
-
setImportError(null);
|
| 97 |
-
|
| 98 |
-
try {
|
| 99 |
-
console.log('Importing from:', importUrl);
|
| 100 |
-
const result = await apiClient.importProject(importUrl);
|
| 101 |
-
|
| 102 |
-
if (result.status === 'success') {
|
| 103 |
-
console.log('Import successful:', result);
|
| 104 |
-
|
| 105 |
-
// Call the onImport callback if provided
|
| 106 |
-
if (onImport && result.code) {
|
| 107 |
-
onImport(result.code, result.language || 'html', importUrl);
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
// Close modal and reset
|
| 111 |
-
setShowImportModal(false);
|
| 112 |
-
setImportUrl('');
|
| 113 |
-
setImportError(null);
|
| 114 |
-
} else {
|
| 115 |
-
setImportError(result.message || 'Import failed');
|
| 116 |
-
}
|
| 117 |
-
} catch (error: any) {
|
| 118 |
-
console.error('Import error:', error);
|
| 119 |
-
setImportError(error.response?.data?.message || error.message || 'Failed to import project');
|
| 120 |
-
} finally {
|
| 121 |
-
setIsImporting(false);
|
| 122 |
-
}
|
| 123 |
-
};
|
| 124 |
-
|
| 125 |
const formatLanguageName = (lang: Language) => {
|
| 126 |
if (lang === 'html') return 'HTML';
|
| 127 |
if (lang === 'transformers.js') return 'Transformers.js';
|
|
@@ -260,78 +218,15 @@ export default function ControlPanel({
|
|
| 260 |
|
| 261 |
{/* Action Buttons */}
|
| 262 |
<div className="flex flex-col space-y-2">
|
| 263 |
-
<button
|
| 264 |
-
onClick={() => setShowImportModal(true)}
|
| 265 |
-
disabled={isGenerating}
|
| 266 |
-
className="w-full px-3 py-2.5 bg-white text-black text-sm rounded-full hover:bg-[#f5f5f7] disabled:opacity-30 disabled:cursor-not-allowed transition-all font-medium flex items-center justify-center active:scale-95"
|
| 267 |
-
>
|
| 268 |
-
Import Project
|
| 269 |
-
</button>
|
| 270 |
<button
|
| 271 |
onClick={onClear}
|
| 272 |
disabled={isGenerating}
|
| 273 |
className="w-full px-3 py-2.5 bg-[#1d1d1f] text-[#f5f5f7] text-sm rounded-full hover:bg-[#2d2d2f] disabled:opacity-30 disabled:cursor-not-allowed transition-all font-medium border border-[#424245]/50 flex items-center justify-center active:scale-95"
|
| 274 |
>
|
| 275 |
-
|
| 276 |
</button>
|
| 277 |
</div>
|
| 278 |
</div>
|
| 279 |
-
|
| 280 |
-
{/* Import Modal */}
|
| 281 |
-
{showImportModal && (
|
| 282 |
-
<div className="fixed inset-0 bg-black/70 backdrop-blur-md flex items-center justify-center z-50 p-4">
|
| 283 |
-
<div className="bg-[#1d1d1f] border border-[#424245] rounded-2xl p-5 max-w-md w-full shadow-2xl">
|
| 284 |
-
<h3 className="text-base font-medium text-[#f5f5f7] mb-4">Import Project</h3>
|
| 285 |
-
|
| 286 |
-
<div className="space-y-3">
|
| 287 |
-
<div>
|
| 288 |
-
<label className="block text-xs font-medium text-[#f5f5f7] mb-2">
|
| 289 |
-
Project URL
|
| 290 |
-
</label>
|
| 291 |
-
<input
|
| 292 |
-
type="text"
|
| 293 |
-
value={importUrl}
|
| 294 |
-
onChange={(e) => setImportUrl(e.target.value)}
|
| 295 |
-
placeholder="https://huggingface.co/spaces/..."
|
| 296 |
-
disabled={isImporting}
|
| 297 |
-
className="w-full px-3 py-2.5 bg-[#000000] text-[#f5f5f7] text-sm border border-[#424245] rounded-lg focus:outline-none focus:border-[#424245] disabled:opacity-40 placeholder-[#86868b]"
|
| 298 |
-
onKeyDown={(e) => e.key === 'Enter' && handleImport()}
|
| 299 |
-
/>
|
| 300 |
-
<p className="text-[10px] text-[#86868b] mt-1.5">
|
| 301 |
-
Supported: HF Spaces, HF Models, GitHub repos
|
| 302 |
-
</p>
|
| 303 |
-
</div>
|
| 304 |
-
|
| 305 |
-
{importError && (
|
| 306 |
-
<div className="p-2.5 bg-[#ff3b30]/10 border border-[#ff3b30]/50 rounded-lg">
|
| 307 |
-
<p className="text-xs text-[#ff3b30]">{importError}</p>
|
| 308 |
-
</div>
|
| 309 |
-
)}
|
| 310 |
-
|
| 311 |
-
<div className="flex gap-2 pt-2">
|
| 312 |
-
<button
|
| 313 |
-
onClick={handleImport}
|
| 314 |
-
disabled={isImporting || !importUrl.trim()}
|
| 315 |
-
className="flex-1 px-3 py-2.5 bg-white text-black text-sm rounded-full hover:bg-[#f5f5f7] disabled:opacity-30 disabled:cursor-not-allowed transition-all font-medium active:scale-95"
|
| 316 |
-
>
|
| 317 |
-
{isImporting ? '⏳ Importing...' : '✓ Import'}
|
| 318 |
-
</button>
|
| 319 |
-
<button
|
| 320 |
-
onClick={() => {
|
| 321 |
-
setShowImportModal(false);
|
| 322 |
-
setImportUrl('');
|
| 323 |
-
setImportError(null);
|
| 324 |
-
}}
|
| 325 |
-
disabled={isImporting}
|
| 326 |
-
className="flex-1 px-3 py-2.5 bg-[#000000] text-[#f5f5f7] text-sm rounded-full hover:bg-[#2d2d2f] disabled:opacity-30 disabled:cursor-not-allowed transition-all font-medium border border-[#424245] active:scale-95"
|
| 327 |
-
>
|
| 328 |
-
Cancel
|
| 329 |
-
</button>
|
| 330 |
-
</div>
|
| 331 |
-
</div>
|
| 332 |
-
</div>
|
| 333 |
-
</div>
|
| 334 |
-
)}
|
| 335 |
</div>
|
| 336 |
);
|
| 337 |
}
|
|
|
|
| 10 |
onLanguageChange: (language: Language) => void;
|
| 11 |
onModelChange: (modelId: string) => void;
|
| 12 |
onClear: () => void;
|
|
|
|
| 13 |
isGenerating: boolean;
|
| 14 |
}
|
| 15 |
|
|
|
|
| 19 |
onLanguageChange,
|
| 20 |
onModelChange,
|
| 21 |
onClear,
|
|
|
|
| 22 |
isGenerating,
|
| 23 |
}: ControlPanelProps) {
|
| 24 |
const [models, setModels] = useState<Model[]>([]);
|
| 25 |
const [languages, setLanguages] = useState<Language[]>([]);
|
| 26 |
const [isLoading, setIsLoading] = useState(true);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
// Dropdown states
|
| 29 |
const [showLanguageDropdown, setShowLanguageDropdown] = useState(false);
|
|
|
|
| 80 |
}
|
| 81 |
};
|
| 82 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
const formatLanguageName = (lang: Language) => {
|
| 84 |
if (lang === 'html') return 'HTML';
|
| 85 |
if (lang === 'transformers.js') return 'Transformers.js';
|
|
|
|
| 218 |
|
| 219 |
{/* Action Buttons */}
|
| 220 |
<div className="flex flex-col space-y-2">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 221 |
<button
|
| 222 |
onClick={onClear}
|
| 223 |
disabled={isGenerating}
|
| 224 |
className="w-full px-3 py-2.5 bg-[#1d1d1f] text-[#f5f5f7] text-sm rounded-full hover:bg-[#2d2d2f] disabled:opacity-30 disabled:cursor-not-allowed transition-all font-medium border border-[#424245]/50 flex items-center justify-center active:scale-95"
|
| 225 |
>
|
| 226 |
+
New Chat
|
| 227 |
</button>
|
| 228 |
</div>
|
| 229 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 230 |
</div>
|
| 231 |
);
|
| 232 |
}
|