add redesign button
Browse files
frontend/src/components/LandingPage.tsx
CHANGED
|
@@ -49,9 +49,11 @@ export default function LandingPage({
|
|
| 49 |
const [showLanguageDropdown, setShowLanguageDropdown] = useState(false);
|
| 50 |
const [showModelDropdown, setShowModelDropdown] = useState(false);
|
| 51 |
const [showImportDialog, setShowImportDialog] = useState(false);
|
|
|
|
| 52 |
const languageDropdownRef = useRef<HTMLDivElement>(null);
|
| 53 |
const modelDropdownRef = useRef<HTMLDivElement>(null);
|
| 54 |
const importDialogRef = useRef<HTMLDivElement>(null);
|
|
|
|
| 55 |
|
| 56 |
// Trending apps state
|
| 57 |
const [trendingApps, setTrendingApps] = useState<any[]>([]);
|
|
@@ -60,6 +62,11 @@ export default function LandingPage({
|
|
| 60 |
const [importUrl, setImportUrl] = useState('');
|
| 61 |
const [isImporting, setIsImporting] = useState(false);
|
| 62 |
const [importError, setImportError] = useState('');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
|
| 64 |
// Debug effect for dropdown state
|
| 65 |
useEffect(() => {
|
|
@@ -156,6 +163,9 @@ export default function LandingPage({
|
|
| 156 |
if (importDialogRef.current && !importDialogRef.current.contains(event.target as Node)) {
|
| 157 |
setShowImportDialog(false);
|
| 158 |
}
|
|
|
|
|
|
|
|
|
|
| 159 |
};
|
| 160 |
|
| 161 |
document.addEventListener('mousedown', handleClickOutside);
|
|
@@ -261,6 +271,51 @@ export default function LandingPage({
|
|
| 261 |
}
|
| 262 |
};
|
| 263 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 264 |
return (
|
| 265 |
<div className="h-screen flex flex-col bg-[#000000] overflow-hidden">
|
| 266 |
{/* Header - Apple style */}
|
|
@@ -509,6 +564,7 @@ export default function LandingPage({
|
|
| 509 |
setShowImportDialog(!showImportDialog);
|
| 510 |
setShowLanguageDropdown(false);
|
| 511 |
setShowModelDropdown(false);
|
|
|
|
| 512 |
setImportError('');
|
| 513 |
}}
|
| 514 |
className="px-3 py-1.5 bg-[#1d1d1f] text-[#f5f5f7] text-xs border border-[#424245] rounded-full hover:bg-[#2d2d2f] transition-all flex items-center gap-1.5 font-medium"
|
|
@@ -565,6 +621,73 @@ export default function LandingPage({
|
|
| 565 |
</div>
|
| 566 |
)}
|
| 567 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 568 |
</div>
|
| 569 |
|
| 570 |
{/* Send button on the right - Apple style */}
|
|
|
|
| 49 |
const [showLanguageDropdown, setShowLanguageDropdown] = useState(false);
|
| 50 |
const [showModelDropdown, setShowModelDropdown] = useState(false);
|
| 51 |
const [showImportDialog, setShowImportDialog] = useState(false);
|
| 52 |
+
const [showRedesignDialog, setShowRedesignDialog] = useState(false);
|
| 53 |
const languageDropdownRef = useRef<HTMLDivElement>(null);
|
| 54 |
const modelDropdownRef = useRef<HTMLDivElement>(null);
|
| 55 |
const importDialogRef = useRef<HTMLDivElement>(null);
|
| 56 |
+
const redesignDialogRef = useRef<HTMLDivElement>(null);
|
| 57 |
|
| 58 |
// Trending apps state
|
| 59 |
const [trendingApps, setTrendingApps] = useState<any[]>([]);
|
|
|
|
| 62 |
const [importUrl, setImportUrl] = useState('');
|
| 63 |
const [isImporting, setIsImporting] = useState(false);
|
| 64 |
const [importError, setImportError] = useState('');
|
| 65 |
+
|
| 66 |
+
// Redesign project state
|
| 67 |
+
const [redesignUrl, setRedesignUrl] = useState('');
|
| 68 |
+
const [isRedesigning, setIsRedesigning] = useState(false);
|
| 69 |
+
const [redesignError, setRedesignError] = useState('');
|
| 70 |
|
| 71 |
// Debug effect for dropdown state
|
| 72 |
useEffect(() => {
|
|
|
|
| 163 |
if (importDialogRef.current && !importDialogRef.current.contains(event.target as Node)) {
|
| 164 |
setShowImportDialog(false);
|
| 165 |
}
|
| 166 |
+
if (redesignDialogRef.current && !redesignDialogRef.current.contains(event.target as Node)) {
|
| 167 |
+
setShowRedesignDialog(false);
|
| 168 |
+
}
|
| 169 |
};
|
| 170 |
|
| 171 |
document.addEventListener('mousedown', handleClickOutside);
|
|
|
|
| 271 |
}
|
| 272 |
};
|
| 273 |
|
| 274 |
+
const handleRedesignProject = async () => {
|
| 275 |
+
if (!redesignUrl.trim()) {
|
| 276 |
+
setRedesignError('Please enter a valid URL');
|
| 277 |
+
return;
|
| 278 |
+
}
|
| 279 |
+
|
| 280 |
+
if (!isAuthenticated) {
|
| 281 |
+
alert('Please sign in with HuggingFace first!');
|
| 282 |
+
return;
|
| 283 |
+
}
|
| 284 |
+
|
| 285 |
+
setIsRedesigning(true);
|
| 286 |
+
setRedesignError('');
|
| 287 |
+
|
| 288 |
+
try {
|
| 289 |
+
const result = await apiClient.importProject(redesignUrl);
|
| 290 |
+
|
| 291 |
+
if (result.status === 'success') {
|
| 292 |
+
// Import the code first, then trigger a redesign
|
| 293 |
+
if (onImport && result.code) {
|
| 294 |
+
onImport(result.code, result.language || 'html', redesignUrl);
|
| 295 |
+
// Automatically trigger a redesign prompt after import
|
| 296 |
+
setTimeout(() => {
|
| 297 |
+
const redesignPrompt = 'Make the app look better with minimal components needed and mobile friendly and modern design';
|
| 298 |
+
onStart(redesignPrompt, result.language || 'html', selectedModel);
|
| 299 |
+
}, 100);
|
| 300 |
+
} else {
|
| 301 |
+
// Fallback: trigger code generation with redesign context
|
| 302 |
+
const redesignMessage = `Redesign this app from ${redesignUrl}: make the app look better with minimal components needed and mobile friendly and modern design`;
|
| 303 |
+
onStart(redesignMessage, result.language || 'html', selectedModel);
|
| 304 |
+
}
|
| 305 |
+
|
| 306 |
+
setShowRedesignDialog(false);
|
| 307 |
+
setRedesignUrl('');
|
| 308 |
+
} else {
|
| 309 |
+
setRedesignError(result.message || 'Failed to import project for redesign');
|
| 310 |
+
}
|
| 311 |
+
} catch (error: any) {
|
| 312 |
+
console.error('Redesign error:', error);
|
| 313 |
+
setRedesignError(error.response?.data?.message || error.message || 'Failed to import project for redesign');
|
| 314 |
+
} finally {
|
| 315 |
+
setIsRedesigning(false);
|
| 316 |
+
}
|
| 317 |
+
};
|
| 318 |
+
|
| 319 |
return (
|
| 320 |
<div className="h-screen flex flex-col bg-[#000000] overflow-hidden">
|
| 321 |
{/* Header - Apple style */}
|
|
|
|
| 564 |
setShowImportDialog(!showImportDialog);
|
| 565 |
setShowLanguageDropdown(false);
|
| 566 |
setShowModelDropdown(false);
|
| 567 |
+
setShowRedesignDialog(false);
|
| 568 |
setImportError('');
|
| 569 |
}}
|
| 570 |
className="px-3 py-1.5 bg-[#1d1d1f] text-[#f5f5f7] text-xs border border-[#424245] rounded-full hover:bg-[#2d2d2f] transition-all flex items-center gap-1.5 font-medium"
|
|
|
|
| 621 |
</div>
|
| 622 |
)}
|
| 623 |
</div>
|
| 624 |
+
|
| 625 |
+
{/* Redesign Project Button */}
|
| 626 |
+
<div className="relative" ref={redesignDialogRef}>
|
| 627 |
+
<button
|
| 628 |
+
type="button"
|
| 629 |
+
onClick={(e) => {
|
| 630 |
+
e.stopPropagation();
|
| 631 |
+
setShowRedesignDialog(!showRedesignDialog);
|
| 632 |
+
setShowLanguageDropdown(false);
|
| 633 |
+
setShowModelDropdown(false);
|
| 634 |
+
setShowImportDialog(false);
|
| 635 |
+
setRedesignError('');
|
| 636 |
+
}}
|
| 637 |
+
className="px-3 py-1.5 bg-[#1d1d1f] text-[#f5f5f7] text-xs border border-[#424245] rounded-full hover:bg-[#2d2d2f] transition-all flex items-center gap-1.5 font-medium"
|
| 638 |
+
>
|
| 639 |
+
<svg className="w-3 h-3" fill="none" stroke="currentColor" viewBox="0 0 24 24" strokeWidth={2.5}>
|
| 640 |
+
<path strokeLinecap="round" strokeLinejoin="round" d="M4 4v5h.582m15.356 2A8.001 8.001 0 004.582 9m0 0H9m11 11v-5h-.581m0 0a8.003 8.003 0 01-15.357-2m15.357 2H15" />
|
| 641 |
+
</svg>
|
| 642 |
+
<span>Redesign</span>
|
| 643 |
+
</button>
|
| 644 |
+
|
| 645 |
+
{/* Redesign Dialog */}
|
| 646 |
+
{showRedesignDialog && (
|
| 647 |
+
<div
|
| 648 |
+
className="absolute top-full left-0 mt-2 w-80 bg-[#1d1d1f] border border-[#424245] rounded-xl shadow-2xl overflow-hidden backdrop-blur-xl z-50"
|
| 649 |
+
onClick={(e) => e.stopPropagation()}
|
| 650 |
+
>
|
| 651 |
+
<div className="p-4">
|
| 652 |
+
<h3 className="text-sm font-medium text-[#f5f5f7] mb-3">Redesign Project</h3>
|
| 653 |
+
<input
|
| 654 |
+
type="text"
|
| 655 |
+
value={redesignUrl}
|
| 656 |
+
onChange={(e) => setRedesignUrl(e.target.value)}
|
| 657 |
+
onKeyPress={(e) => e.key === 'Enter' && handleRedesignProject()}
|
| 658 |
+
placeholder="https://huggingface.co/spaces/..."
|
| 659 |
+
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"
|
| 660 |
+
disabled={isRedesigning}
|
| 661 |
+
/>
|
| 662 |
+
{redesignError && (
|
| 663 |
+
<p className="text-xs text-red-400 mb-2">{redesignError}</p>
|
| 664 |
+
)}
|
| 665 |
+
<div className="flex gap-2">
|
| 666 |
+
<button
|
| 667 |
+
onClick={handleRedesignProject}
|
| 668 |
+
disabled={isRedesigning || !redesignUrl.trim()}
|
| 669 |
+
className="flex-1 px-3 py-2 bg-white text-black rounded-lg text-xs hover:bg-[#f5f5f7] disabled:opacity-50 disabled:cursor-not-allowed font-medium"
|
| 670 |
+
>
|
| 671 |
+
{isRedesigning ? 'Redesigning...' : 'Redesign'}
|
| 672 |
+
</button>
|
| 673 |
+
<button
|
| 674 |
+
onClick={() => {
|
| 675 |
+
setShowRedesignDialog(false);
|
| 676 |
+
setRedesignUrl('');
|
| 677 |
+
setRedesignError('');
|
| 678 |
+
}}
|
| 679 |
+
className="px-3 py-2 bg-[#2d2d30] text-[#f5f5f7] rounded-lg text-xs hover:bg-[#3d3d3f] font-medium"
|
| 680 |
+
>
|
| 681 |
+
Cancel
|
| 682 |
+
</button>
|
| 683 |
+
</div>
|
| 684 |
+
<p className="text-[10px] text-[#86868b] mt-3">
|
| 685 |
+
Import and automatically redesign with modern, mobile-friendly design
|
| 686 |
+
</p>
|
| 687 |
+
</div>
|
| 688 |
+
</div>
|
| 689 |
+
)}
|
| 690 |
+
</div>
|
| 691 |
</div>
|
| 692 |
|
| 693 |
{/* Send button on the right - Apple style */}
|