import { useState } from 'react'; import ChatList from './components/ChatList'; import ChatWindow from './components/ChatWindow'; import Settings from './components/Settings'; import useLocalStorage from './hooks/useLocalStorage'; function App() { const [profiles, setProfiles] = useLocalStorage('profiles', [ { id: 'default', name: 'Default Profile', apiEndpoint: '', apiKey: '', model: 'DeepSeek-R1' } ]); const [summarizationProfile, setSummarizationProfile] = useLocalStorage('summarizationProfile', { id: 'default-summarization-profile', name: 'Summarization Profile', apiEndpoint: '', apiKey: '', model: 'DeepSeek-R1' }); const [activeProfileId, setActiveProfileId] = useLocalStorage('activeProfileId', 'default'); const [chats, setChats] = useLocalStorage('chats', []); const [currentChatId, setCurrentChatId] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const [showSettings, setShowSettings] = useState(false); const [sidebarCollapsed, setSidebarCollapsed] = useState(false); const [showProfileDropdown, setShowProfileDropdown] = useState(false); const [mobileMenuOpen, setMobileMenuOpen] = useState(false); const activeProfile = profiles.find(p => p.id === activeProfileId) || profiles[0]; const createNewChat = () => { const newChat = { id: Date.now(), title: 'New Conversation', messages: [] }; setChats([...chats, newChat]); setCurrentChatId(newChat.id); }; const deleteChat = (chatId) => { setChats(chats.filter(chat => chat.id !== chatId)); if (currentChatId === chatId) { setCurrentChatId(null); } }; const toggleSettings = () => { setShowSettings(!showSettings); }; const toggleSidebar = () => { setSidebarCollapsed(!sidebarCollapsed); // 在移动设备上,如果侧边栏是展开的,点击收起按钮也应该关闭移动菜单 if (window.innerWidth <= 768 && !sidebarCollapsed) { setMobileMenuOpen(false); } }; const toggleMobileMenu = () => { setMobileMenuOpen(!mobileMenuOpen); // 如果侧边栏是收起的,则展开它 if (sidebarCollapsed) { setSidebarCollapsed(false); } }; const toggleProfileDropdown = () => { setShowProfileDropdown(!showProfileDropdown); }; const handleProfileSelect = (profileId) => { setActiveProfileId(profileId); setShowProfileDropdown(false); }; return (
Start a new conversation or select an existing one.