Files
AgentCompany/src/renderer/hooks/useSectionContext.ts
T
ZacharyZhang-NY e2253b92fa refactor(renderer): dismantle useAppController 47-prop god-hook
Sections now subscribe directly to the Zustand store via useSectionContext
(shared data derivation) and useAppStore fine-grained selectors. Delete
useAppController, useExecutionController, useOrganizationController, and
useCommunicationController; the three domain forwarders held no logic
beyond re-exporting store slices.

SectionContentView becomes a 50-line layout dispatcher taking only
{section, error, pageTransition}; cross-domain run actions (startRun /
cancelRun) move into App.tsx and are exposed to sections through a new
AppActionsContext alongside refresh / setError / openPathWithFeedback.
App.tsx now calls useUIController + useCompanyController directly and
composes palette + navigation plumbing itself.
2026-04-16 22:12:51 -04:00

41 lines
1.2 KiB
TypeScript

import { useMemo } from "react";
import type { CompanyRecord } from "@shared/types";
import { useAppStore } from "../state/store";
import { useCompanyData } from "./useCompanyData";
/**
* Shared data context for section views. Subscribes to the Zustand store
* for snapshot + current company, derives per-company collections and
* currently-selected entities via useCompanyData.
*
* Sections call this hook directly instead of receiving 30+ props through
* SectionContentView.
*/
export function useSectionContext() {
const snapshot = useAppStore((s) => s.snapshot);
const currentCompany = useMemo<CompanyRecord | null>(() => {
if (!snapshot) return null;
return (
snapshot.companies.find((company) => company.id === snapshot.currentCompanyId) ??
snapshot.companies[0] ??
null
);
}, [snapshot]);
const companyData = useCompanyData(snapshot, currentCompany);
const selectedConnectorId = useAppStore((s) => s.selectedConnectorId);
const selectedConnector =
snapshot?.connectors.find((connector) => connector.id === selectedConnectorId) ??
snapshot?.connectors[0] ??
null;
return {
snapshot,
currentCompany,
selectedConnector,
...companyData,
};
}