| 6 | import { generateId } from '@/lib/utils'; |
| 7 | |
| 8 | function App() { |
| 9 | const addSession = useSessionStore((s) => s.addSession); |
| 10 | const setActiveSessionId = useSessionStore((s) => s.setActiveSessionId); |
| 11 | const activeProjectId = useProjectStore((s) => s.activeProjectId); |
| 12 | const theme = useUIStore((s) => s.theme); |
| 13 | |
| 14 | // Apply theme class to document root |
| 15 | useEffect(() => { |
| 16 | const root = document.documentElement; |
| 17 | if (theme === 'light') { |
| 18 | root.classList.add('light'); |
| 19 | } else { |
| 20 | root.classList.remove('light'); |
| 21 | } |
| 22 | }, [theme]); |
| 23 | |
| 24 | useEffect(() => { |
| 25 | const handleKeyDown = (e: KeyboardEvent) => { |
| 26 | if ((e.metaKey || e.ctrlKey) && e.key === 'n') { |
| 27 | e.preventDefault(); |
| 28 | const session = { |
| 29 | id: generateId(), |
| 30 | projectId: activeProjectId ?? 'default', |
| 31 | title: 'New Chat', |
| 32 | createdAt: new Date().toISOString(), |
| 33 | updatedAt: new Date().toISOString(), |
| 34 | }; |
| 35 | addSession(session); |
| 36 | setActiveSessionId(session.id); |
| 37 | } |
| 38 | }; |
| 39 | |
| 40 | window.addEventListener('keydown', handleKeyDown); |
| 41 | return () => window.removeEventListener('keydown', handleKeyDown); |
| 42 | }, [activeProjectId, addSession, setActiveSessionId]); |
| 43 | |
| 44 | return <AppShell />; |
| 45 | } |
| 46 | |
| 47 | export default App; |