Spaces:
Running
Running
axeronis commited on
Commit ·
3fc8a71
1
Parent(s): b9f9102
fix: Demo-chat mobile layout fixed viewport
Browse files27 unmodified lines28293031323320 unmodified lines5455565758596022 unmodified lines838485868788895 unmodified lines95969798991001012 unmodified lines1041051061071081091102 unmodified lines11311411511611711811912012112212312412512612712812913013121 unmodified lines1531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232243 unmodified lines2282292302312322332342352362372382392402412422432442452462472482492502513 unmodified lines2552562572582592602612622632642652662672682692702712722732742752762772782 unmodified lines2812822832842852862872882892902912922932942952962973 unmodified lines3013023033043053063073083093103113123133143153163173183193203213223233243253263272 unmodified lines3303313323333343353363371 unmodified line33934034134234334434534634734834935035135235335435535635727 unmodified linesconst messagesEndRef = useRef<HTMLDivElement>(null)const inputRef = useRef<HTMLInputElement>(null)// Scroll to bottom on new messagesuseEffect(() => {messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })20 unmodified lines}])toast.success('Настройки обновлены!')} else {// Fallback to simple correctionsetCorrections(prev => [...prev, correction])setMessages(prev => [...prev, {id: crypto.randomUUID(),22 unmodified linesconst userInput = input.trim()setInput('')// Check for correction mode or commandif (isCorrectMode || userInput.startsWith('/правка:') || userInput.startsWith('/fix:')) {const correction = isCorrectMode? userInput5 unmodified linesreturn}// Add user messageconst userMessage: DemoMessage = {id: crypto.randomUUID(),role: 'user',2 unmodified lines}setMessages(prev => [...prev, userMessage])// Generate AI responsesetIsLoading(true)try {const response = await api.post('/api/v1/demo/chat', {2 unmodified linescorrections: corrections})const aiMessage: DemoMessage = {id: crypto.randomUUID(),role: 'ai',content: response.data.response,timestamp: new Date()}setMessages(prev => [...prev, aiMessage])} catch (error: any) {toast.error(error.response?.data?.detail || 'Ошибка генерации')setMessages(prev => [...prev, {id: crypto.randomUUID(),role: 'ai',content: '⚠️ Не удалось сгенерировать ответ.',timestamp: new Date()}])} finally {21 unmodified linesif (authLoading) {return (<div className="flex items-center justify-center h-screen bg-[#0a0a0f]"><Loader2 className="w-8 h-8 animate-spin text-violet-500" /></div>)}return (<div className="min-h-screen bg-[#0a0a0f] flex flex-col">{/* Header - Clean & Modern */}<header className="flex items-center justify-between px-4 py-3 md:px-6 md:py-4 border-b border-white/5 bg-gradient-to-r from-[#0a0a0f] to-[#0f0f1a]"><div className="flex items-center gap-3"><Linkhref="/settings/brain"className="p-2 text-white/40 hover:text-white hover:bg-white/5 rounded-lg transition-all"><ArrowLeft className="w-5 h-5" /></Link><div className="w-10 h-10 rounded-xl bg-gradient-to-br from-violet-600 to-purple-700 flex items-center justify-center shadow-lg shadow-violet-500/20"><Bot className="w-5 h-5 text-white" /></div><div className="hidden sm:block"><h1 className="font-semibold text-white text-sm">Демо-чат</h1><p className="text-[11px] text-white/40">Тест без сохранения</p></div></div><div className="flex items-center gap-2"><buttononClick={clearChat}className="p-2 text-white/40 hover:text-white hover:bg-white/5 rounded-lg transition-all"><Trash2 className="w-4 h-4" /></button><Linkhref="/settings/brain"className="hidden sm:flex items-center gap-2 px-3 py-1.5 text-xs text-white/60 hover:text-white bg-white/5 hover:bg-white/10 rounded-lg transition-all"><Settings className="w-3.5 h-3.5" />AI Мозг</Link></div></header>{/* Messages Area */}<div className="flex-1 overflow-y-auto"><div className="max-w-2xl mx-auto px-4 py-6 space-y-4">{messages.length === 0 ? (<div className="flex flex-col items-center justify-center min-h-[60vh] text-center"><div className="w-16 h-16 rounded-2xl bg-gradient-to-br from-violet-600/20 to-purple-600/20 flex items-center justify-center mb-4 border border-violet-500/10"><Sparkles className="w-8 h-8 text-violet-400" /></div><h3 className="text-lg font-semibold text-white mb-1">Протестируй AI</h3><p className="text-sm text-white/40 max-w-sm mb-6">Пиши как клиент. Нажми <span className="text-violet-400">🪄</span> чтобы скорректировать бота.</p><div className="grid gap-2 text-left w-full max-w-sm"><buttononClick={() => setInput('Привет, расскажи о ваших услугах')}className="p-3 bg-white/5 hover:bg-white/10 border border-white/5 rounded-xl text-sm text-white/70 hover:text-white transition-all text-left">💬 "Привет, расскажи о ваших услугах"</button><buttononClick={() => setInput('Сколько стоит?')}className="p-3 bg-white/5 hover:bg-white/10 border border-white/5 rounded-xl text-sm text-white/70 hover:text-white transition-all text-left">💰 "Сколько стоит?"</button>3 unmodified linesmessages.map((msg) => (<motion.divkey={msg.id}initial={{ opacity: 0, y: 10 }}animate={{ opacity: 1, y: 0 }}className={cn("flex gap-3",msg.role === 'user' && "flex-row-reverse",msg.role === 'system' && "justify-center")}>{msg.role === 'system' ? (<div className="px-4 py-2 bg-violet-500/10 border border-violet-500/20 rounded-xl"><div className="flex items-center gap-2 text-violet-300 text-sm"><CheckCircle className="w-4 h-4" /><span>{msg.content}</span></div>{msg.changes && msg.changes.length > 0 && (<div className="mt-2 flex flex-wrap gap-1">{msg.changes.map((c, i) => (<span key={i} className="px-2 py-0.5 bg-violet-500/20 text-violet-200 text-[10px] rounded-full">{c.field}: {c.value}</span>))}3 unmodified lines) : (<><div className={cn("w-8 h-8 rounded-lg flex items-center justify-center flex-shrink-0",msg.role === 'user'? "bg-white/10": "bg-gradient-to-br from-violet-600 to-purple-700")}>{msg.role === 'user' ? (<User className="w-4 h-4 text-white/70" />) : (<Bot className="w-4 h-4 text-white" />)}</div><div className={cn("max-w-[80%] px-4 py-3 rounded-2xl text-sm",msg.role === 'user'? "bg-violet-600 text-white rounded-br-md": "bg-white/5 text-white/90 border border-white/5 rounded-bl-md")}><p className="whitespace-pre-wrap leading-relaxed">{msg.content}</p></div></>)}2 unmodified lines)}{isLoading && (<div className="flex gap-3"><div className="w-8 h-8 rounded-lg bg-gradient-to-br from-violet-600 to-purple-700 flex items-center justify-center"><Bot className="w-4 h-4 text-white" /></div><div className="bg-white/5 border border-white/5 px-4 py-3 rounded-2xl rounded-bl-md"><div className="flex items-center gap-2"><div className="flex gap-1"><span className="w-2 h-2 bg-violet-400 rounded-full animate-bounce" style={{ animationDelay: '0ms' }} /><span className="w-2 h-2 bg-violet-400 rounded-full animate-bounce" style={{ animationDelay: '150ms' }} /><span className="w-2 h-2 bg-violet-400 rounded-full animate-bounce" style={{ animationDelay: '300ms' }} /></div></div></div></div>3 unmodified lines</div></div>{/* Input Area - Modern & Clean */}<div className="border-t border-white/5 bg-gradient-to-r from-[#0a0a0f] to-[#0f0f1a]"><div className="max-w-2xl mx-auto px-4 py-3"><div className={cn("flex items-center gap-2 p-1.5 rounded-2xl transition-all",isCorrectMode? "bg-violet-500/10 border-2 border-violet-500/30": "bg-white/5 border border-white/5")}>{/* Magic Wand Button */}<buttononClick={toggleCorrectMode}className={cn("p-2.5 rounded-xl transition-all flex-shrink-0",isCorrectMode? "bg-violet-500 text-white shadow-lg shadow-violet-500/30": "text-white/40 hover:text-violet-400 hover:bg-violet-500/10")}title="Режим правки"><Wand2 className="w-5 h-5" /></button><input2 unmodified linesvalue={input}onChange={(e) => setInput(e.target.value)}onKeyPress={handleKeyPress}placeholder={isCorrectMode ? "Опиши что исправить..." : "Напиши сообщение..."}className="flex-1 bg-transparent text-white placeholder-white/30 focus:outline-none text-sm px-2"disabled={isLoading}/>1 unmodified lineonClick={handleSend}disabled={!input.trim() || isLoading}className={cn("p-2.5 rounded-xl transition-all flex-shrink-0",input.trim()? "bg-violet-600 hover:bg-violet-500 text-white": "bg-white/5 text-white/20")}><Send className="w-5 h-5" /></button></div>{isCorrectMode && (<p className="text-center text-[11px] text-violet-400/80 mt-2">🪄 Режим правки: опиши что изменить (напр. "не говори бот", "ты Анна")</p>)}</div>27 unmodified lines282930313233343536373839404120 unmodified lines62636465666722 unmodified lines9091929394955 unmodified lines1011021031041051062 unmodified lines1091101111121131142 unmodified lines11711811912012112212312412512612712812913013113213313421 unmodified lines1561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132143 unmodified lines2182192202212222232242252262272282292302312322332342352362372382392402413 unmodified lines2452462472482492502512522532542552562572582592602612622632642652662 unmodified lines2692702712722732742752762772782792802812822833 unmodified lines2872882892902912922932942952962972982993003013023033043053063073083093103112 unmodified lines3143153163173183193203211 unmodified line32332432532632732832933033133233333433533633733833934034127 unmodified linesconst messagesEndRef = useRef<HTMLDivElement>(null)const inputRef = useRef<HTMLInputElement>(null)// Lock body scroll on mountuseEffect(() => {document.body.style.overflow = 'hidden'return () => {document.body.style.overflow = ''}}, [])// Scroll to bottom on new messagesuseEffect(() => {messagesEndRef.current?.scrollIntoView({ behavior: 'smooth' })20 unmodified lines}])toast.success('Настройки обновлены!')} else {setCorrections(prev => [...prev, correction])setMessages(prev => [...prev, {id: crypto.randomUUID(),22 unmodified linesconst userInput = input.trim()setInput('')if (isCorrectMode || userInput.startsWith('/правка:') || userInput.startsWith('/fix:')) {const correction = isCorrectMode? userInput5 unmodified linesreturn}const userMessage: DemoMessage = {id: crypto.randomUUID(),role: 'user',2 unmodified lines}setMessages(prev => [...prev, userMessage])setIsLoading(true)try {const response = await api.post('/api/v1/demo/chat', {2 unmodified linescorrections: corrections})setMessages(prev => [...prev, {id: crypto.randomUUID(),role: 'ai',content: response.data.response,timestamp: new Date()}])} catch (error: any) {toast.error('Ошибка генерации')setMessages(prev => [...prev, {id: crypto.randomUUID(),role: 'ai',content: '⚠️ Ошибка. Проверьте настройки AI.',timestamp: new Date()}])} finally {21 unmodified linesif (authLoading) {return (<div className="fixed inset-0 flex items-center justify-center bg-[#0a0a0f]"><Loader2 className="w-8 h-8 animate-spin text-violet-500" /></div>)}return (<div className="fixed inset-0 bg-[#0a0a0f] flex flex-col overflow-hidden">{/* Header */}<header className="flex-shrink-0 flex items-center justify-between px-3 py-2 sm:px-4 sm:py-3 border-b border-white/5 bg-[#0a0a0f]"><div className="flex items-center gap-2 sm:gap-3"><Link href="/settings/brain" className="p-1.5 sm:p-2 text-white/40 hover:text-white rounded-lg"><ArrowLeft className="w-5 h-5" /></Link><div className="w-8 h-8 sm:w-10 sm:h-10 rounded-xl bg-gradient-to-br from-violet-600 to-purple-700 flex items-center justify-center"><Bot className="w-4 h-4 sm:w-5 sm:h-5 text-white" /></div><div><h1 className="font-semibold text-white text-sm">Демо-чат</h1><p className="text-[10px] text-white/40 hidden sm:block">Тест без сохранения</p></div></div><div className="flex items-center gap-1 sm:gap-2"><button onClick={clearChat} className="p-1.5 sm:p-2 text-white/40 hover:text-white rounded-lg"><Trash2 className="w-4 h-4" /></button></div></header>{/* Messages - Scrollable area */}<div className="flex-1 overflow-y-auto overscroll-contain"><div className="max-w-2xl mx-auto px-3 sm:px-4 py-4 space-y-3">{messages.length === 0 ? (<div className="flex flex-col items-center justify-center min-h-[50vh] text-center px-4"><div className="w-14 h-14 rounded-2xl bg-gradient-to-br from-violet-600/20 to-purple-600/20 flex items-center justify-center mb-3 border border-violet-500/10"><Sparkles className="w-7 h-7 text-violet-400" /></div><h3 className="text-base font-semibold text-white mb-1">Тест AI</h3><p className="text-xs text-white/40 max-w-xs mb-4">Пиши как клиент. 🪄 — режим правки.</p><div className="grid gap-2 w-full max-w-sm"><buttononClick={() => setInput('Привет!')}className="p-2.5 bg-white/5 border border-white/5 rounded-xl text-xs text-white/70 text-left">💬 "Привет!"</button><buttononClick={() => setInput('Сколько стоит?')}className="p-2.5 bg-white/5 border border-white/5 rounded-xl text-xs text-white/70 text-left">💰 "Сколько стоит?"</button>3 unmodified linesmessages.map((msg) => (<motion.divkey={msg.id}initial={{ opacity: 0, y: 5 }}animate={{ opacity: 1, y: 0 }}className={cn("flex gap-2",msg.role === 'user' && "flex-row-reverse",msg.role === 'system' && "justify-center")}>{msg.role === 'system' ? (<div className="px-3 py-2 bg-violet-500/10 border border-violet-500/20 rounded-xl max-w-[90%]"><div className="flex items-center gap-2 text-violet-300 text-xs"><CheckCircle className="w-3.5 h-3.5 flex-shrink-0" /><span>{msg.content}</span></div>{msg.changes && msg.changes.length > 0 && (<div className="mt-1.5 flex flex-wrap gap-1">{msg.changes.map((c, i) => (<span key={i} className="px-1.5 py-0.5 bg-violet-500/20 text-violet-200 text-[10px] rounded-full">{c.field}: {c.value}</span>))}3 unmodified lines) : (<><div className={cn("w-7 h-7 rounded-lg flex items-center justify-center flex-shrink-0",msg.role === 'user' ? "bg-white/10" : "bg-gradient-to-br from-violet-600 to-purple-700")}>{msg.role === 'user' ? (<User className="w-3.5 h-3.5 text-white/70" />) : (<Bot className="w-3.5 h-3.5 text-white" />)}</div><div className={cn("max-w-[80%] px-3 py-2 rounded-2xl text-sm",msg.role === 'user'? "bg-violet-600 text-white rounded-br-md": "bg-white/5 text-white/90 border border-white/5 rounded-bl-md")}><p className="whitespace-pre-wrap text-[13px] leading-relaxed">{msg.content}</p></div></>)}2 unmodified lines)}{isLoading && (<div className="flex gap-2"><div className="w-7 h-7 rounded-lg bg-gradient-to-br from-violet-600 to-purple-700 flex items-center justify-center"><Bot className="w-3.5 h-3.5 text-white" /></div><div className="bg-white/5 border border-white/5 px-3 py-2 rounded-2xl rounded-bl-md"><div className="flex gap-1"><span className="w-1.5 h-1.5 bg-violet-400 rounded-full animate-bounce" style={{ animationDelay: '0ms' }} /><span className="w-1.5 h-1.5 bg-violet-400 rounded-full animate-bounce" style={{ animationDelay: '150ms' }} /><span className="w-1.5 h-1.5 bg-violet-400 rounded-full animate-bounce" style={{ animationDelay: '300ms' }} /></div></div></div>3 unmodified lines</div></div>{/* Input - Fixed at bottom */}<div className="flex-shrink-0 border-t border-white/5 bg-[#0a0a0f] px-3 py-2 sm:px-4 sm:py-3 safe-area-bottom"><div className="max-w-2xl mx-auto"><div className={cn("flex items-center gap-1.5 p-1 rounded-xl transition-all",isCorrectMode? "bg-violet-500/10 border-2 border-violet-500/30": "bg-white/5 border border-white/5")}><buttononClick={toggleCorrectMode}className={cn("p-2 rounded-lg transition-all flex-shrink-0",isCorrectMode? "bg-violet-500 text-white": "text-white/40 hover:text-violet-400")}><Wand2 className="w-4 h-4 sm:w-5 sm:h-5" /></button><input2 unmodified linesvalue={input}onChange={(e) => setInput(e.target.value)}onKeyPress={handleKeyPress}placeholder={isCorrectMode ? "Что исправить..." : "Сообщение..."}className="flex-1 bg-transparent text-white placeholder-white/30 focus:outline-none text-sm px-1 min-w-0"disabled={isLoading}/>1 unmodified lineonClick={handleSend}disabled={!input.trim() || isLoading}className={cn("p-2 rounded-lg transition-all flex-shrink-0",input.trim()? "bg-violet-600 text-white": "bg-white/5 text-white/20")}><Send className="w-4 h-4 sm:w-5 sm:h-5" /></button></div>{isCorrectMode && (<p className="text-center text-[10px] text-violet-400/80 mt-1.5">🪄 Опиши правку: "не говори бот", "ты Анна"</p>)}</div>
frontend/app/demo-chat/page.tsx+74-90