Commit 459309cd authored by AGLANPC\aglan's avatar AGLANPC\aglan

fgg dfjdfghj dfkj df

parent e636c018
This diff is collapsed.
...@@ -3,22 +3,11 @@ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; ...@@ -3,22 +3,11 @@ import { Prism as SyntaxHighlighter } from "react-syntax-highlighter";
import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism"; import { oneDark } from "react-syntax-highlighter/dist/esm/styles/prism";
import { Copy, Check, Download, FileCode } from "lucide-react"; import { Copy, Check, Download, FileCode } from "lucide-react";
// Map common aliases for syntax highlighting
const LANG_MAP = { const LANG_MAP = {
cs: "csharp", cs: "csharp", sh: "bash", shell: "bash", yml: "yaml",
sh: "bash", dockerfile: "docker", jsx: "jsx", tsx: "tsx", py: "python",
shell: "bash", js: "javascript", ts: "typescript", rb: "ruby", rs: "rust",
yml: "yaml", kt: "kotlin", gd: "gdscript",
dockerfile: "docker",
jsx: "jsx",
tsx: "tsx",
py: "python",
js: "javascript",
ts: "typescript",
rb: "ruby",
rs: "rust",
kt: "kotlin",
gd: "gdscript",
}; };
const customStyle = { const customStyle = {
...@@ -28,19 +17,18 @@ const customStyle = { ...@@ -28,19 +17,18 @@ const customStyle = {
background: "#0d0d14", background: "#0d0d14",
margin: 0, margin: 0,
borderRadius: 0, borderRadius: 0,
fontSize: "0.82rem", fontSize: "0.78rem",
lineHeight: "1.6", lineHeight: "1.55",
}, },
'code[class*="language-"]': { 'code[class*="language-"]': {
...oneDark['code[class*="language-"]'], ...oneDark['code[class*="language-"]'],
background: "none", background: "none",
fontSize: "0.82rem", fontSize: "0.78rem",
}, },
}; };
export default function CodeBlock({ language, filename, code }) { export default function CodeBlock({ language, filename, code }) {
const [copied, setCopied] = useState(false); const [copied, setCopied] = useState(false);
const hlLang = LANG_MAP[language] || language || "text"; const hlLang = LANG_MAP[language] || language || "text";
function handleCopy() { function handleCopy() {
...@@ -61,46 +49,44 @@ export default function CodeBlock({ language, filename, code }) { ...@@ -61,46 +49,44 @@ export default function CodeBlock({ language, filename, code }) {
} }
return ( return (
<div className="my-3 rounded-lg overflow-hidden border border-anton-border bg-[#0d0d14]"> <div className="my-2.5 rounded-lg overflow-hidden border border-anton-border bg-[#0d0d14]">
{/* Header bar */} {/* Header */}
<div className="flex items-center justify-between px-3 py-1.5 bg-anton-border/30"> <div className="flex items-center justify-between px-2.5 sm:px-3 py-1.5 bg-anton-border/30 gap-2">
<div className="flex items-center gap-2 text-xs text-anton-muted"> <div className="flex items-center gap-1.5 text-xs text-anton-muted min-w-0">
<FileCode size={12} className="text-anton-accent" /> <FileCode size={11} className="text-anton-accent shrink-0" />
{filename ? ( {filename ? (
<span className="text-anton-text font-mono">{filename}</span> <span className="text-anton-text font-mono truncate text-[11px]">{filename}</span>
) : ( ) : (
<span>{hlLang}</span> <span className="text-[11px]">{hlLang}</span>
)} )}
</div> </div>
<div className="flex items-center gap-1"> <div className="flex items-center gap-0.5 shrink-0">
<button onClick={handleCopy} <button
className="flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-anton-muted hover:text-white hover:bg-anton-card transition" onClick={handleCopy}
className="flex items-center gap-1 px-2 py-1 rounded text-[10px] text-anton-muted hover:text-white hover:bg-anton-card transition min-h-[28px]"
> >
{copied ? <Check size={11} className="text-anton-success" /> : <Copy size={11} />} {copied ? <Check size={10} className="text-anton-success" /> : <Copy size={10} />}
{copied ? "Copied" : "Copy"} <span className="hidden sm:inline">{copied ? "Copied" : "Copy"}</span>
</button> </button>
<button onClick={handleDownload} <button
className="flex items-center gap-1 px-2 py-0.5 rounded text-[11px] text-anton-muted hover:text-anton-accent hover:bg-anton-accent/10 transition" onClick={handleDownload}
className="flex items-center gap-1 px-2 py-1 rounded text-[10px] text-anton-muted hover:text-anton-accent hover:bg-anton-accent/10 transition min-h-[28px]"
> >
<Download size={11} /> <Download size={10} />
Download <span className="hidden sm:inline">Download</span>
</button> </button>
</div> </div>
</div> </div>
{/* Code */} {/* Code with horizontal scroll */}
<div className="overflow-x-auto"> <div className="overflow-x-auto overscroll-x-contain -webkit-overflow-scrolling-touch">
<SyntaxHighlighter <SyntaxHighlighter
language={hlLang} language={hlLang}
style={customStyle} style={customStyle}
showLineNumbers showLineNumbers={code.split("\n").length > 3}
lineNumberStyle={{ lineNumberStyle={{ color: "#333", fontSize: "0.7rem", minWidth: "2em", paddingRight: "0.5em" }}
minWidth: "2.5em", customStyle={{ padding: "0.75rem", minWidth: "fit-content" }}
paddingRight: "1em", wrapLongLines={false}
color: "#3a3a4a",
userSelect: "none",
}}
wrapLines
> >
{code} {code}
</SyntaxHighlighter> </SyntaxHighlighter>
......
...@@ -5,10 +5,12 @@ import CodeBlock from "./CodeBlock"; ...@@ -5,10 +5,12 @@ import CodeBlock from "./CodeBlock";
import { getAttachmentUrl } from "../api"; import { getAttachmentUrl } from "../api";
import { import {
User, Flame, ChevronDown, ChevronRight, Brain, Copy, Check, User, Flame, ChevronDown, ChevronRight, Brain, Copy, Check,
Image, Film, FileText, ExternalLink, FileCode, File, Image, Film, FileText, ExternalLink,
} from "lucide-react"; } from "lucide-react";
const FILE_TYPE_ICONS = { image: Image, video: Film, document: FileText, text: FileCode }; const FILE_TYPE_ICONS = {
image: Image, video: Film, document: FileText, text: FileText,
};
const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, isThinking, token }) { const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, isThinking, token }) {
const { role, content, thinking_content, input_tokens, output_tokens, attachments } = message; const { role, content, thinking_content, input_tokens, output_tokens, attachments } = message;
...@@ -35,20 +37,20 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, ...@@ -35,20 +37,20 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming,
</div> </div>
)} )}
<div className={`max-w-[92%] sm:max-w-[80%] min-w-0 ${isUser ? "order-first" : ""}`}> <div className={`min-w-0 ${isUser ? "max-w-[85%] sm:max-w-[75%]" : "max-w-[90%] sm:max-w-[80%]"}`}>
{/* Thinking block */} {/* Thinking block */}
{thinking_content && ( {thinking_content && (
<div className="mb-2"> <div className="mb-2">
<button <button
onClick={() => setShowThinking(!showThinking)} onClick={() => setShowThinking(!showThinking)}
className="flex items-center gap-1.5 text-xs text-purple-400 hover:text-purple-300 transition mb-1" className="flex items-center gap-1.5 text-xs text-purple-400 hover:text-purple-300 transition mb-1 min-h-[32px]"
> >
<Brain size={12} /> <Brain size={12} />
{showThinking ? <ChevronDown size={12} /> : <ChevronRight size={12} />} {showThinking ? <ChevronDown size={12} /> : <ChevronRight size={12} />}
{isThinking ? <span className="thinking-pulse">Reasoning…</span> : <span>View reasoning</span>} {isThinking ? <span className="thinking-pulse">Reasoning…</span> : <span>View reasoning</span>}
</button> </button>
{(showThinking || isThinking) && ( {(showThinking || isThinking) && (
<div className="bg-purple-500/5 border border-purple-500/20 rounded-lg p-2.5 text-xs text-purple-300/80 font-mono whitespace-pre-wrap max-h-48 sm:max-h-60 overflow-y-auto"> <div className="bg-purple-500/5 border border-purple-500/20 rounded-lg p-2.5 sm:p-3 text-xs text-purple-300/80 font-mono whitespace-pre-wrap max-h-48 sm:max-h-60 overflow-y-auto overscroll-contain break-words">
{thinking_content} {thinking_content}
{isThinking && <span className="inline-block w-1.5 h-4 bg-purple-400 ml-0.5 animate-pulse" />} {isThinking && <span className="inline-block w-1.5 h-4 bg-purple-400 ml-0.5 animate-pulse" />}
</div> </div>
...@@ -60,22 +62,22 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, ...@@ -60,22 +62,22 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming,
{hasAttachments && ( {hasAttachments && (
<div className="mb-2 flex flex-wrap gap-1.5"> <div className="mb-2 flex flex-wrap gap-1.5">
{attachments.map((att) => { {attachments.map((att) => {
const Icon = FILE_TYPE_ICONS[att.file_type] || File; const Icon = FILE_TYPE_ICONS[att.file_type] || FileText;
const url = getAttachmentUrl(att.id); const url = getAttachmentUrl(att.id);
if (att.file_type === "image") { if (att.file_type === "image") {
return ( return (
<div key={att.id} className="relative group"> <div key={att.id} className="relative">
<img <img
src={`${url}?token=${token}`} src={`${url}?token=${token}`}
alt={att.original_filename} alt={att.original_filename}
className="max-w-[180px] sm:max-w-[260px] max-h-[140px] sm:max-h-[200px] rounded-lg border border-anton-border object-cover cursor-pointer hover:opacity-90 transition shadow-md" className="max-w-[200px] sm:max-w-[240px] max-h-[160px] sm:max-h-[200px] rounded-lg border border-anton-border object-cover cursor-pointer hover:opacity-90 transition"
onClick={() => setExpandedImage(expandedImage === att.id ? null : att.id)} onClick={() => setExpandedImage(expandedImage === att.id ? null : att.id)}
onError={(e) => { e.target.style.display = "none"; }} onError={(e) => { e.target.style.display = "none"; }}
/> />
{expandedImage === att.id && ( {expandedImage === att.id && (
<div <div
className="fixed inset-0 z-50 bg-black/85 flex items-center justify-center p-4 cursor-pointer" className="fixed inset-0 z-50 bg-black/80 flex items-center justify-center p-4 sm:p-8 cursor-pointer"
onClick={() => setExpandedImage(null)} onClick={() => setExpandedImage(null)}
> >
<img <img
...@@ -85,7 +87,7 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, ...@@ -85,7 +87,7 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming,
/> />
</div> </div>
)} )}
<div className="absolute bottom-1 left-1 bg-black/60 text-[8px] text-white px-1.5 py-0.5 rounded max-w-[90%] truncate"> <div className="absolute bottom-1 left-1 bg-black/60 text-[8px] text-white px-1 py-0.5 rounded">
{att.original_filename} {att.original_filename}
</div> </div>
</div> </div>
...@@ -98,14 +100,14 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, ...@@ -98,14 +100,14 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming,
href={`${url}?token=${token}`} href={`${url}?token=${token}`}
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
className="flex items-center gap-2 bg-anton-card border border-anton-border rounded-lg px-2.5 py-2 hover:border-anton-accent transition group max-w-[200px]" className="flex items-center gap-2 bg-anton-card border border-anton-border rounded-lg px-2.5 py-2 hover:border-anton-accent transition group min-h-[44px]"
> >
<Icon size={15} className="shrink-0 text-blue-400" /> <Icon size={14} className="shrink-0 text-blue-400" />
<div className="min-w-0 flex-1"> <div className="min-w-0">
<div className="text-[11px] text-white truncate">{att.original_filename}</div> <div className="text-xs text-white truncate max-w-[120px] sm:max-w-[160px]">{att.original_filename}</div>
<div className="text-[9px] text-anton-muted">{(att.file_size / 1024).toFixed(0)}KB</div> <div className="text-[9px] text-anton-muted">{(att.file_size / 1024).toFixed(0)}KB</div>
</div> </div>
<ExternalLink size={11} className="text-anton-muted group-hover:text-anton-accent shrink-0" /> <ExternalLink size={10} className="text-anton-muted group-hover:text-anton-accent shrink-0" />
</a> </a>
); );
})} })}
...@@ -113,14 +115,15 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, ...@@ -113,14 +115,15 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming,
)} )}
{/* Message bubble */} {/* Message bubble */}
<div className={`rounded-2xl px-3.5 py-2.5 sm:px-4 sm:py-3 ${isUser <div className={`rounded-2xl px-3.5 py-2.5 sm:px-4 sm:py-3 ${
? "bg-anton-accent text-white rounded-br-md" isUser
: "bg-anton-card border border-anton-border rounded-bl-md" ? "bg-anton-accent text-white rounded-br-md"
}`}> : "bg-anton-card border border-anton-border rounded-bl-md"
}`}>
{isUser ? ( {isUser ? (
<div className="text-sm whitespace-pre-wrap break-words">{_stripPrefixes(content)}</div> <div className="text-sm whitespace-pre-wrap break-words leading-relaxed">{_stripPrefixes(content)}</div>
) : ( ) : (
<div className="prose-anton text-sm break-words"> <div className="prose-anton text-sm">
<ReactMarkdown <ReactMarkdown
remarkPlugins={[remarkGfm]} remarkPlugins={[remarkGfm]}
components={{ components={{
...@@ -148,16 +151,19 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming, ...@@ -148,16 +151,19 @@ const MessageBubble = React.memo(function MessageBubble({ message, isStreaming,
)} )}
</div> </div>
{/* Meta info */} {/* Actions */}
{!isUser && !isStreaming && content && ( {!isUser && !isStreaming && content && (
<div className="flex items-center gap-3 mt-1.5 px-1 flex-wrap"> <div className="flex items-center gap-3 mt-1 px-1">
<button onClick={handleCopy} className="flex items-center gap-1 text-[10px] sm:text-[11px] text-anton-muted hover:text-white transition"> <button
{copied ? <Check size={11} className="text-anton-success" /> : <Copy size={11} />} onClick={handleCopy}
className="flex items-center gap-1 text-[10px] text-anton-muted hover:text-white transition min-h-[28px]"
>
{copied ? <Check size={10} className="text-anton-success" /> : <Copy size={10} />}
{copied ? "Copied" : "Copy"} {copied ? "Copied" : "Copy"}
</button> </button>
{(input_tokens > 0 || output_tokens > 0) && ( {(input_tokens > 0 || output_tokens > 0) && (
<span className="text-[10px] sm:text-[11px] text-anton-muted"> <span className="text-[10px] text-anton-muted">
{input_tokens?.toLocaleString()}/ {output_tokens?.toLocaleString()} {input_tokens?.toLocaleString()}{output_tokens?.toLocaleString()}
</span> </span>
)} )}
</div> </div>
......
This diff is collapsed.
This diff is collapsed.
import React, { useEffect, useState } from "react"; import React, { useEffect } from "react";
import { useApp } from "../store"; import { useApp } from "../store";
import { listChats, createChat } from "../api"; import { listChats, createChat } from "../api";
import Sidebar from "../components/Sidebar"; import Sidebar from "../components/Sidebar";
import ChatView from "../components/ChatView"; import ChatView from "../components/ChatView";
import { Flame, BookOpen, Shield } from "lucide-react"; import { Flame, Menu, Plus, MessageSquare } from "lucide-react";
import { useNavigate } from "react-router-dom";
export default function ChatPage() { export default function ChatPage() {
const { state, dispatch } = useApp(); const { state, dispatch } = useApp();
const navigate = useNavigate();
const [activeChatId, setActiveChatId] = useState(null);
const [sidebarOpen, setSidebarOpen] = useState(false);
useEffect(() => { useEffect(() => {
(async () => { (async () => {
try { try {
const chats = await listChats(state.token); const chats = await listChats(state.token);
dispatch({ type: "SET_CHATS", chats }); dispatch({ type: "SET_CHATS", chats });
if (chats.length > 0 && !activeChatId) { if (!state.activeChatId && chats.length > 0) {
setActiveChatId(chats[0].id); dispatch({ type: "SET_ACTIVE_CHAT", chatId: chats[0].id });
} }
} catch { } } catch { /* ignore */ }
})(); })();
}, [state.token, dispatch]); }, [state.token]);
async function handleNewChat() { async function handleNewChat() {
try { try {
const chat = await createChat(state.token); const chat = await createChat(state.token);
dispatch({ type: "ADD_CHAT", chat }); dispatch({ type: "ADD_CHAT", chat });
setActiveChatId(chat.id); } catch { /* ignore */ }
setSidebarOpen(false);
} catch { }
}
function handleSelectChat(chatId) {
setActiveChatId(chatId);
setSidebarOpen(false);
} }
return ( return (
<div className="h-dvh flex bg-anton-bg text-anton-text overflow-hidden"> <div className="h-full h-dvh flex overflow-hidden bg-anton-bg">
{/* Sidebar */} {/* Desktop sidebar */}
<Sidebar <div className="hidden sm:flex">
activeChatId={activeChatId} <Sidebar />
onSelectChat={handleSelectChat} </div>
onNewChat={handleNewChat}
isOpen={sidebarOpen} {/* Mobile sidebar overlay */}
onClose={() => setSidebarOpen(false)} {state.sidebarOpen && (
/> <>
<div
className="sm:hidden fixed inset-0 z-40 bg-black/60 animate-overlay-in"
onClick={() => dispatch({ type: "SET_SIDEBAR_OPEN", open: false })}
/>
<div className="sm:hidden fixed inset-y-0 left-0 z-50 w-[280px] animate-slide-in safe-top safe-bottom">
<Sidebar mobile onClose={() => dispatch({ type: "SET_SIDEBAR_OPEN", open: false })} />
</div>
</>
)}
{/* Main */} {/* Main content */}
<div className="flex-1 flex flex-col min-h-0 min-w-0"> <div className="flex-1 flex flex-col min-w-0">
{/* Top bar */} {/* Mobile header */}
<div className="border-b border-anton-border bg-anton-surface px-3 py-2 flex items-center gap-2"> <div className="sm:hidden flex items-center gap-2 px-3 py-2.5 border-b border-anton-border bg-anton-surface safe-top">
<button onClick={() => setSidebarOpen(true)} className="sm:hidden p-1.5 rounded-lg text-anton-muted hover:text-white hover:bg-anton-card transition"> <button
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round"><line x1="3" y1="6" x2="21" y2="6" /><line x1="3" y1="12" x2="21" y2="12" /><line x1="3" y1="18" x2="21" y2="18" /></svg> onClick={() => dispatch({ type: "TOGGLE_SIDEBAR" })}
className="p-2 -ml-1 rounded-lg text-anton-muted hover:text-white hover:bg-anton-card transition active:scale-95"
>
<Menu size={20} />
</button> </button>
<div className="w-7 h-7 rounded-lg bg-gradient-to-br from-anton-accent to-red-600 flex items-center justify-center"> <div className="flex-1 min-w-0 flex items-center gap-2">
<Flame size={14} className="text-white" /> <div className="w-6 h-6 rounded-md bg-gradient-to-br from-anton-accent to-red-600 flex items-center justify-center shrink-0">
<Flame size={12} className="text-white" />
</div>
<span className="text-sm font-medium text-white truncate">
{state.chats.find((c) => c.id === state.activeChatId)?.title || "Son of Anton"}
</span>
</div> </div>
<span className="text-sm font-semibold text-white truncate flex-1">
{state.chats.find((c) => c.id === activeChatId)?.title || "Son of Anton"}
</span>
<button <button
onClick={() => navigate("/knowledge")} onClick={handleNewChat}
className="flex items-center gap-1 px-2 py-1 rounded-lg text-xs text-anton-muted hover:text-green-400 hover:bg-green-500/10 transition" className="p-2 -mr-1 rounded-lg text-anton-muted hover:text-white hover:bg-anton-card transition active:scale-95"
title="Knowledge Bases"
> >
<BookOpen size={14} /> <Plus size={20} />
<span className="hidden sm:inline">Knowledge</span>
</button> </button>
{state.user?.role === "superadmin" && (
<button
onClick={() => navigate("/admin")}
className="flex items-center gap-1 px-2 py-1 rounded-lg text-xs text-anton-muted hover:text-anton-accent hover:bg-anton-accent/10 transition"
title="Admin Panel"
>
<Shield size={14} />
<span className="hidden sm:inline">Admin</span>
</button>
)}
</div> </div>
{/* Chat area */} {/* Chat or empty state */}
{activeChatId ? ( {state.activeChatId ? (
<ChatView chatId={activeChatId} /> <ChatView chatId={state.activeChatId} />
) : ( ) : (
<div className="flex-1 flex items-center justify-center"> <div className="flex-1 flex items-center justify-center p-6">
<div className="text-center"> <div className="text-center max-w-sm">
<div className="w-16 h-16 rounded-2xl bg-gradient-to-br from-anton-accent to-red-600 flex items-center justify-center mx-auto mb-4 shadow-lg shadow-anton-accent/20"> <div className="w-16 h-16 mx-auto mb-4 rounded-2xl bg-gradient-to-br from-anton-accent to-red-600 flex items-center justify-center shadow-lg shadow-anton-accent/20">
<Flame size={32} className="text-white" /> <Flame size={32} className="text-white" />
</div> </div>
<h2 className="text-xl font-bold text-white mb-2">Son of Anton</h2> <h2 className="text-xl font-bold text-white mb-2">Son of Anton</h2>
<p className="text-anton-muted text-sm mb-6">Avatar of All Elements of Code</p> <p className="text-anton-muted text-sm mb-6">
<button onClick={handleNewChat} className="px-6 py-2.5 rounded-xl bg-anton-accent text-white font-medium hover:opacity-80 transition"> Avatar of All Elements of Code
Start a Chat </p>
<button
onClick={handleNewChat}
className="inline-flex items-center gap-2 px-5 py-3 bg-anton-accent text-white rounded-xl font-medium hover:opacity-90 transition active:scale-95"
>
<MessageSquare size={18} /> Start a conversation
</button> </button>
</div> </div>
</div> </div>
......
import React, { useState } from "react"; import React, { useState } from "react";
import { Flame, LogIn, UserPlus, Eye, EyeOff } from "lucide-react";
import { login, register } from "../api";
import { useApp } from "../store"; import { useApp } from "../store";
import { login, register } from "../api";
import { Flame, Eye, EyeOff, Loader2 } from "lucide-react";
export default function LoginPage() { export default function LoginPage() {
const { dispatch } = useApp(); const { dispatch } = useApp();
...@@ -18,132 +18,104 @@ export default function LoginPage() { ...@@ -18,132 +18,104 @@ export default function LoginPage() {
setError(""); setError("");
setLoading(true); setLoading(true);
try { try {
let res; const res = isRegister
if (isRegister) { ? await register(username, email, password)
res = await register(username, email, password); : await login(username, password);
} else {
res = await login(username, password);
}
dispatch({ type: "LOGIN", token: res.token, user: res.user }); dispatch({ type: "LOGIN", token: res.token, user: res.user });
} catch (err) { } catch (err) {
setError(err.message); setError(err.message || "Authentication failed");
} finally { } finally {
setLoading(false); setLoading(false);
} }
} }
return ( return (
<div className="h-full flex items-center justify-center bg-anton-bg p-4"> <div className="h-full h-dvh flex items-center justify-center bg-anton-bg px-4 safe-top safe-bottom">
{/* Glow effect */} <div className="w-full max-w-sm">
<div className="absolute top-1/3 left-1/2 -translate-x-1/2 -translate-y-1/2 w-[500px] h-[500px] bg-anton-accent/5 rounded-full blur-[120px] pointer-events-none" /> {/* Logo */}
<div className="relative w-full max-w-md animate-fade-in">
{/* Header */}
<div className="text-center mb-8"> <div className="text-center mb-8">
<div className="inline-flex items-center justify-center w-20 h-20 rounded-2xl bg-gradient-to-br from-anton-accent to-red-600 mb-4 shadow-lg shadow-anton-accent/20"> <div className="w-16 h-16 mx-auto mb-4 rounded-2xl bg-gradient-to-br from-anton-accent to-red-600 flex items-center justify-center shadow-lg shadow-anton-accent/20">
<Flame size={40} className="text-white" /> <Flame size={32} className="text-white" />
</div> </div>
<h1 className="text-3xl font-bold text-white tracking-tight"> <h1 className="text-2xl font-bold text-white">Son of Anton</h1>
Son of Anton <p className="text-anton-muted text-sm mt-1">Avatar of All Elements of Code</p>
</h1>
<p className="text-anton-muted mt-2 text-sm">
Avatar of All Elements of Code
</p>
</div> </div>
{/* Form Card */} {/* Form */}
<form <form onSubmit={handleSubmit} className="space-y-4">
onSubmit={handleSubmit}
className="bg-anton-surface border border-anton-border rounded-2xl p-8 space-y-5 shadow-2xl"
>
<h2 className="text-xl font-semibold text-white text-center">
{isRegister ? "Create Account" : "Welcome Back"}
</h2>
{error && (
<div className="bg-red-500/10 border border-red-500/30 text-red-400 text-sm rounded-lg p-3">
{error}
</div>
)}
<div> <div>
<label className="block text-sm text-anton-muted mb-1.5">Username</label> <label className="text-xs text-anton-muted mb-1.5 block">Username</label>
<input <input
type="text" type="text"
value={username} value={username}
onChange={(e) => setUsername(e.target.value)} onChange={(e) => setUsername(e.target.value)}
required className="w-full bg-anton-card border border-anton-border rounded-xl px-4 py-3 text-white focus:outline-none focus:border-anton-accent transition"
className="w-full bg-anton-bg border border-anton-border rounded-lg px-4 py-2.5 text-white focus:outline-none focus:border-anton-accent transition"
placeholder="Enter username" placeholder="Enter username"
required
autoComplete="username"
autoCapitalize="off"
/> />
</div> </div>
{isRegister && ( {isRegister && (
<div> <div>
<label className="block text-sm text-anton-muted mb-1.5">Email</label> <label className="text-xs text-anton-muted mb-1.5 block">Email</label>
<input <input
type="email" type="email"
value={email} value={email}
onChange={(e) => setEmail(e.target.value)} onChange={(e) => setEmail(e.target.value)}
className="w-full bg-anton-card border border-anton-border rounded-xl px-4 py-3 text-white focus:outline-none focus:border-anton-accent transition"
placeholder="your@email.com"
required required
className="w-full bg-anton-bg border border-anton-border rounded-lg px-4 py-2.5 text-white focus:outline-none focus:border-anton-accent transition" autoComplete="email"
placeholder="you@example.com"
/> />
</div> </div>
)} )}
<div> <div>
<label className="block text-sm text-anton-muted mb-1.5">Password</label> <label className="text-xs text-anton-muted mb-1.5 block">Password</label>
<div className="relative"> <div className="relative">
<input <input
type={showPw ? "text" : "password"} type={showPw ? "text" : "password"}
value={password} value={password}
onChange={(e) => setPassword(e.target.value)} onChange={(e) => setPassword(e.target.value)}
required className="w-full bg-anton-card border border-anton-border rounded-xl px-4 py-3 pr-12 text-white focus:outline-none focus:border-anton-accent transition"
className="w-full bg-anton-bg border border-anton-border rounded-lg px-4 py-2.5 pr-10 text-white focus:outline-none focus:border-anton-accent transition"
placeholder="••••••••" placeholder="••••••••"
required
autoComplete={isRegister ? "new-password" : "current-password"}
/> />
<button <button
type="button" type="button"
onClick={() => setShowPw(!showPw)} onClick={() => setShowPw(!showPw)}
className="absolute right-3 top-1/2 -translate-y-1/2 text-anton-muted hover:text-white transition" className="absolute right-3 top-1/2 -translate-y-1/2 text-anton-muted hover:text-white transition p-1"
> >
{showPw ? <EyeOff size={16} /> : <Eye size={16} />} {showPw ? <EyeOff size={18} /> : <Eye size={18} />}
</button> </button>
</div> </div>
</div> </div>
{error && (
<div className="bg-anton-danger/10 border border-anton-danger/30 text-anton-danger text-sm rounded-lg px-3 py-2.5">
{error}
</div>
)}
<button <button
type="submit" type="submit"
disabled={loading} disabled={loading}
className="w-full bg-gradient-to-r from-anton-accent to-orange-600 text-white font-semibold rounded-lg py-2.5 hover:opacity-90 transition disabled:opacity-50 flex items-center justify-center gap-2" className="w-full py-3.5 bg-anton-accent text-white rounded-xl font-semibold hover:opacity-90 transition disabled:opacity-50 active:scale-[0.98] flex items-center justify-center gap-2"
> >
{loading ? ( {loading && <Loader2 size={18} className="animate-spin" />}
<div className="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" /> {isRegister ? "Create Account" : "Sign In"}
) : isRegister ? (
<>
<UserPlus size={18} /> Create Account
</>
) : (
<>
<LogIn size={18} /> Sign In
</>
)}
</button> </button>
<p className="text-center text-sm text-anton-muted"> <button
{isRegister ? "Already have an account?" : "Don't have an account?"}{" "} type="button"
<button onClick={() => { setIsRegister(!isRegister); setError(""); }}
type="button" className="w-full text-center text-sm text-anton-muted hover:text-white transition py-2"
onClick={() => { >
setIsRegister(!isRegister); {isRegister ? "Already have an account? Sign in" : "Need an account? Register"}
setError(""); </button>
}}
className="text-anton-accent hover:underline"
>
{isRegister ? "Sign in" : "Register"}
</button>
</p>
</form> </form>
</div> </div>
</div> </div>
......
import React, { createContext, useContext, useReducer, useEffect } from "react"; import React, { createContext, useContext, useReducer, useCallback } from "react";
const AppContext = createContext(null); const AppContext = createContext(null);
...@@ -6,10 +6,10 @@ const initialState = { ...@@ -6,10 +6,10 @@ const initialState = {
token: localStorage.getItem("token") || null, token: localStorage.getItem("token") || null,
user: null, user: null,
chats: [], chats: [],
activeChatId: null,
chatMessages: {}, chatMessages: {},
activeStreams: {}, activeStreams: {},
sidebarOpen: false, sidebarOpen: false,
sidebarTab: "chats", // "chats" | "knowledge"
}; };
function reducer(state, action) { function reducer(state, action) {
...@@ -17,18 +17,23 @@ function reducer(state, action) { ...@@ -17,18 +17,23 @@ function reducer(state, action) {
case "LOGIN": case "LOGIN":
localStorage.setItem("token", action.token); localStorage.setItem("token", action.token);
return { ...state, token: action.token, user: action.user }; return { ...state, token: action.token, user: action.user };
case "SET_TOKEN":
localStorage.setItem("token", action.token);
return { ...state, token: action.token };
case "SET_USER":
return { ...state, user: action.user };
case "LOGOUT": case "LOGOUT":
localStorage.removeItem("token"); localStorage.removeItem("token");
return { ...initialState, token: null }; return { ...initialState, token: null };
case "SET_USER":
return { ...state, user: action.user };
case "SET_CHATS": case "SET_CHATS":
return { ...state, chats: action.chats }; return { ...state, chats: action.chats };
case "SET_ACTIVE_CHAT":
return { ...state, activeChatId: action.chatId, sidebarOpen: false };
case "ADD_CHAT": case "ADD_CHAT":
return { ...state, chats: [action.chat, ...state.chats] }; return {
...state,
chats: [action.chat, ...state.chats],
activeChatId: action.chat.id,
sidebarOpen: false,
};
case "UPDATE_CHAT": case "UPDATE_CHAT":
return { return {
...state, ...state,
...@@ -36,47 +41,49 @@ function reducer(state, action) { ...@@ -36,47 +41,49 @@ function reducer(state, action) {
c.id === action.chat.id ? { ...c, ...action.chat } : c c.id === action.chat.id ? { ...c, ...action.chat } : c
), ),
}; };
case "REMOVE_CHAT": case "REMOVE_CHAT": {
const remaining = state.chats.filter((c) => c.id !== action.chatId);
return { return {
...state, ...state,
chats: state.chats.filter((c) => c.id !== action.chatId), chats: remaining,
chatMessages: (() => { activeChatId:
const m = { ...state.chatMessages }; state.activeChatId === action.chatId
delete m[action.chatId]; ? remaining[0]?.id || null
return m; : state.activeChatId,
})(),
}; };
}
case "SET_MESSAGES": case "SET_MESSAGES":
return { return {
...state, ...state,
chatMessages: { ...state.chatMessages, [action.chatId]: action.messages }, chatMessages: { ...state.chatMessages, [action.chatId]: action.messages },
}; };
case "ADD_MESSAGE": case "ADD_MESSAGE": {
const prev = state.chatMessages[action.chatId] || [];
return { return {
...state, ...state,
chatMessages: { chatMessages: {
...state.chatMessages, ...state.chatMessages,
[action.chatId]: [ [action.chatId]: [...prev, action.message],
...(state.chatMessages[action.chatId] || []),
action.message,
],
}, },
}; };
}
case "SET_STREAMING": case "SET_STREAMING":
return { return {
...state, ...state,
activeStreams: action.streaming activeStreams: action.streaming
? { ...state.activeStreams, [action.chatId]: true } ? { ...state.activeStreams, [action.chatId]: true }
: (() => { : Object.fromEntries(
const s = { ...state.activeStreams }; Object.entries(state.activeStreams).filter(([k]) => k !== action.chatId)
delete s[action.chatId]; ),
return s;
})(),
}; };
case "SET_SIDEBAR_OPEN": case "SET_SIDEBAR_OPEN":
return { ...state, sidebarOpen: action.open }; return { ...state, sidebarOpen: action.open };
case "SET_SIDEBAR_TAB": case "TOGGLE_SIDEBAR":
return { ...state, sidebarTab: action.tab }; return { ...state, sidebarOpen: !state.sidebarOpen };
default: default:
return state; return state;
} }
...@@ -93,6 +100,6 @@ export function AppProvider({ children }) { ...@@ -93,6 +100,6 @@ export function AppProvider({ children }) {
export function useApp() { export function useApp() {
const ctx = useContext(AppContext); const ctx = useContext(AppContext);
if (!ctx) throw new Error("useApp must be used within AppProvider"); if (!ctx) throw new Error("useApp must be inside AppProvider");
return ctx; return ctx;
} }
\ No newline at end of file
...@@ -5,18 +5,21 @@ export default { ...@@ -5,18 +5,21 @@ export default {
extend: { extend: {
colors: { colors: {
"anton-bg": "#09090f", "anton-bg": "#09090f",
"anton-surface": "#0d0d14", "anton-surface": "#0f0f1a",
"anton-card": "#12121c", "anton-card": "#16162a",
"anton-border": "#1e1e2e", "anton-border": "#1e1e3a",
"anton-text": "#e0e0e0", "anton-text": "#e2e2ea",
"anton-muted": "#6b6b80", "anton-muted": "#6b6b8a",
"anton-accent": "#ff4444", "anton-accent": "#e53e3e",
"anton-success": "#22c55e", "anton-success": "#48bb78",
"anton-danger": "#ef4444", "anton-danger": "#e53e3e",
}, },
fontFamily: { fontFamily: {
sans: ["Inter", "system-ui", "sans-serif"], sans: ["Inter", "system-ui", "-apple-system", "sans-serif"],
mono: ["JetBrains Mono", "Consolas", "monospace"], mono: ["JetBrains Mono", "Fira Code", "monospace"],
},
screens: {
"xs": "400px",
}, },
}, },
}, },
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment