Open History to see the last commit
1import { useEffect, useMemo, useRef } from "react";
2
3import ChatView from "./components/ChatView";
4import DiffPanel from "./components/DiffPanel";
5import Sidebar from "./components/Sidebar";
6import { readNativeApi } from "./session-logic";
7import { StoreProvider, useStore } from "./store";
8
9function EventRouter() {
10 const api = useMemo(() => readNativeApi(), []);
11 const { dispatch } = useStore();
12 const activeAssistantItemRef = useRef<string | null>(null);
13
14 useEffect(() => {
15 if (!api) return;
16 return api.providers.onEvent((event) => {
17 dispatch({
18 type: "APPLY_EVENT",
19 event,
20 activeAssistantItemRef,
21 });
22 });
23 }, [api, dispatch]);
24
25 return null;
26}
27
28function Layout() {
29 const api = useMemo(() => readNativeApi(), []);
30 const { state } = useStore();
31
32 if (!api) {
33 return (
34 <div className="flex h-screen flex-col bg-[#0c0c0c] text-[#e0e0e0]">
35 <div className="drag-region h-[52px] shrink-0" />
36 <div className="flex flex-1 items-center justify-center">
37 <p className="text-sm text-[#a0a0a0]/60">
38 Native bridge unavailable. Launch through Electron.
39 </p>
40 </div>
41 </div>
42 );
43 }
44
45 return (
46 <div className="flex h-screen overflow-hidden bg-[#0c0c0c] text-[#e0e0e0]">
47 <EventRouter />
48 <Sidebar />
49 <ChatView />
50 {state.diffOpen && <DiffPanel />}
51 </div>
52 );
53}
54
55export default function App() {
56 return (
57 <StoreProvider>
58 <Layout />
59 </StoreProvider>
60 );
61}