add image upload
Browse filesFiles changed (2)
58 unmodified lines596061626364652 unmodified lines6869707172737475767778798058 unmodified lines const loadModels = async () => { try { const modelsList = await apiClient.getModels(); console.log('[Models] Loaded models:', modelsList); setModels(modelsList); } catch (error) { console.error('Failed to load models:', error);2 unmodified lines // Check if current model supports images const currentModelSupportsImages = models.find(m => m.id === selectedModel)?.supports_images || false; // Debug log for image support useEffect(() => { console.log('[Image Support] Selected model:', selectedModel); console.log('[Image Support] Models loaded:', models.length); console.log('[Image Support] Supports images:', currentModelSupportsImages); }, [selectedModel, models, currentModelSupportsImages]);
// Load messages from localStorage on mount (client-side only to avoid hydration issues) useEffect(() => {123456723 unmodified lines313233333435363737 unmodified lines75767778798081828384131 unmodified lines2162172182192202212222232248 unmodified lines233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263410 unmodified lines674675676677678679680681682683684685686687688689690691692693694695696697698699700701702361 unmodified lines1064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094'use client';
import { useState, useEffect, useRef } from 'react';import Image from 'next/image';import { apiClient } from '@/lib/api';import { initializeOAuth, 23 unmodified lines onImport, isAuthenticated, initialLanguage = 'html', initialModel = 'deepseek-ai/DeepSeek-V3.2-Exp', initialModel = 'zai-org/GLM-4.6V:zai-org', onAuthChange, setPendingPR, pendingPRRef37 unmodified lines const [isRedesigning, setIsRedesigning] = useState(false); const [redesignError, setRedesignError] = useState(''); const [createPR, setCreatePR] = useState(false); // Default to normal redesign (not PR) // Image upload state const [uploadedImageUrl, setUploadedImageUrl] = useState<string | null>(null); const fileInputRef = useRef<HTMLInputElement>(null);
// Debug effect for dropdown state useEffect(() => {131 unmodified lines console.error('Failed to load languages:', error); } }; // Check if current model supports images const currentModelSupportsImages = models.find(m => m.id === selectedModel)?.supports_images || false;
const loadTrendingApps = async () => { try {8 unmodified lines e.preventDefault(); if (prompt.trim() && isAuthenticated) { onStart(prompt.trim(), selectedLanguage, selectedModel); // Clear image after sending setUploadedImageUrl(null); } else if (!isAuthenticated) { alert('Please sign in with HuggingFace first!'); } }; const handleImageUpload = (e: React.ChangeEvent<HTMLInputElement>) => { const file = e.target.files?.[0]; if (file) { const reader = new FileReader(); reader.onload = (event) => { const imageUrl = event.target?.result as string; setUploadedImageUrl(imageUrl); }; reader.readAsDataURL(file); } }; const removeImage = () => { setUploadedImageUrl(null); if (fileInputRef.current) { fileInputRef.current.value = ''; } };
const formatLanguageName = (lang: Language) => { if (lang === 'html') return 'HTML';410 unmodified lines {/* Simple prompt form */} <form onSubmit={handleSubmit} className="relative w-full mb-8"> <div className="relative bg-[#2d2d30] rounded-2xl border border-[#424245] shadow-2xl"> {/* Image Preview */} {uploadedImageUrl && ( <div className="px-4 pt-3"> <div className="relative inline-block"> <Image src={uploadedImageUrl} alt="Upload preview" width={120} height={120} className="rounded-lg object-cover" unoptimized /> <button type="button" onClick={removeImage} className="absolute -top-2 -right-2 w-6 h-6 bg-red-500 text-white rounded-full hover:bg-red-600 transition-all flex items-center justify-center text-xs font-bold" > × </button> </div> </div> )} {/* Textarea */} <textarea value={prompt}361 unmodified lines </div> </div>
{/* Image Upload Button (only if model supports images) */} {currentModelSupportsImages && ( <> <input ref={fileInputRef} type="file" accept="image/*" onChange={handleImageUpload} className="hidden" disabled={!isAuthenticated} /> <button type="button" onClick={() => fileInputRef.current?.click()} disabled={!isAuthenticated} className="p-2 bg-[#1d1d1f] text-[#f5f5f7] rounded-full hover:bg-[#424245] disabled:opacity-30 disabled:cursor-not-allowed transition-all active:scale-95" title="Upload image" > <svg className="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24" strokeWidth={2.5}> <path strokeLinecap="round" strokeLinejoin="round" d="M2.25 15.75l5.159-5.159a2.25 2.25 0 013.182 0l5.159 5.159m-1.5-1.5l1.409-1.409a2.25 2.25 0 013.182 0l2.909 2.909m-18 3.75h16.5a1.5 1.5 0 001.5-1.5V6a1.5 1.5 0 00-1.5-1.5H3.75A1.5 1.5 0 002.25 6v12a1.5 1.5 0 001.5 1.5zm10.5-11.25h.008v.008h-.008V8.25zm.375 0a.375.375 0 11-.75 0 .375.375 0 01.75 0z" /> </svg> </button> </> )} {/* Send button on the right - Apple style */} <button type="submit"frontend/src/app/page.tsx+8
frontend/src/components/LandingPage.tsx+78-1