import { useState, useRef, useEffect, type FormEvent } from 'react'; import { useNavigate } from 'react-router-dom'; import { Send, Settings, LogOut, PenLine, BarChart3, Megaphone, MessageCircle } from 'lucide-react'; import { useAuth } from '../hooks/useAuth'; import { useSocket } from '../hooks/useSocket'; import AICompanion from '../components/AICompanion'; import ChatBubble from '../components/ChatBubble'; export default function DashboardPage() { const navigate = useNavigate(); const { user, token, isAuthenticated, logout } = useAuth(); const { messages, sendMessage, connected } = useSocket(token); const [input, setInput] = useState(''); const chatEndRef = useRef(null); useEffect(() => { if (!isAuthenticated) { navigate('/login'); } }, [isAuthenticated, navigate]); useEffect(() => { chatEndRef.current?.scrollIntoView({ behavior: 'smooth' }); }, [messages]); const handleSend = (e: FormEvent) => { e.preventDefault(); if (!input.trim()) return; sendMessage(input.trim()); setInput(''); }; const handleLogout = () => { logout(); navigate('/'); }; if (!user) return null; const companionName = user.aiCompanion?.name || 'AI伙伴'; const roleLabel = user.role === 'author' ? '作者' : user.role === 'editor' ? '编辑' : '运营'; return (
{/* Header */}
🌟 光湖码字
{user.nickname}({roleLabel})
{/* Main chat area */}
{/* AI Companion avatar */}
{connected ? ( ● 已连接 ) : ( ○ 连接中... )}
{/* Chat messages */}
{messages.map((msg, idx) => ( ))}
{/* Input area */}
setInput(e.target.value)} placeholder={`和${companionName}说点什么...`} className="flex-1 px-4 py-2.5 outline-none text-ink-800 text-sm bg-transparent" />
{/* Quick actions */}
{[ { icon: PenLine, label: '开始写作' }, { icon: BarChart3, label: '查看数据' }, { icon: Megaphone, label: '看定制书需求' }, { icon: MessageCircle, label: '讨论区' }, ].map((action) => ( ))}
); }