diff --git a/src/App.tsx b/src/App.tsx index 7925cb3..5f9e615 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,10 @@ -import { useMemo, useState } from "react"; -import { initialWorkspaces, selectWorkspace } from "./workspace"; +import { useReducer } from "react"; +import { + createInitialWorkspaceState, + selectActiveTab, + selectActiveWorkspace, + workspaceReducer, +} from "./workspace"; const sessions = [ { id: "NW-042", status: "ONLINE", host: "ws-fin-042", user: "nora.chen", os: "Windows 11", address: "10.42.8.17", seen: "14s ago", tags: ["finance", "priority"] }, @@ -9,25 +14,19 @@ const sessions = [ ]; export function App() { - const [activeServerId, setActiveServerId] = useState(initialWorkspaces[0].id); - const [activeTabs, setActiveTabs] = useState>( - Object.fromEntries(initialWorkspaces.map((server) => [server.id, server.activeTabId])), - ); - const server = useMemo( - () => selectWorkspace(initialWorkspaces, activeServerId) ?? initialWorkspaces[0], - [activeServerId], - ); - const activeTab = server.tabs.find((tab) => tab.id === activeTabs[server.id]) ?? server.tabs[0]; + const [workspace, dispatch] = useReducer(workspaceReducer, undefined, createInitialWorkspaceState); + const server = selectActiveWorkspace(workspace); + const activeTab = selectActiveTab(server); return (