refactor(useCompanyController): drop eslint-disable comments via getState() in callbacks (P2-24)
setters now read inline via useAppStore.getState() so exhaustive-deps rule is satisfied without disables; 7 disable comments removed.
This commit is contained in:
1 parent
4aaf0b8bfe
commit
95c9deb778
1 file changed
+22
-36
@@ -14,17 +14,6 @@ export function useCompanyController() {
|
|||||||
const selectedRunId = useAppStore((s) => s.selectedRunId);
|
const selectedRunId = useAppStore((s) => s.selectedRunId);
|
||||||
const locale = useAppStore((s) => s.locale);
|
const locale = useAppStore((s) => s.locale);
|
||||||
const incrementLogRevision = useAppStore((s) => s.incrementLogRevision);
|
const incrementLogRevision = useAppStore((s) => s.incrementLogRevision);
|
||||||
const {
|
|
||||||
setError,
|
|
||||||
setInitialOnboardingLocked,
|
|
||||||
setSection,
|
|
||||||
setShowOnboarding,
|
|
||||||
setSelectedRunId,
|
|
||||||
setSelectedAgentId,
|
|
||||||
setConfirmDeleteCompanyId,
|
|
||||||
setCompanySwitcherOpen,
|
|
||||||
setLocale,
|
|
||||||
} = useAppStore.getState();
|
|
||||||
|
|
||||||
const currentCompany = useMemo<CompanyRecord | null>(() => {
|
const currentCompany = useMemo<CompanyRecord | null>(() => {
|
||||||
if (!snapshot) return null;
|
if (!snapshot) return null;
|
||||||
@@ -71,13 +60,12 @@ export function useCompanyController() {
|
|||||||
root.style.colorScheme = isDark ? "dark" : "light";
|
root.style.colorScheme = isDark ? "dark" : "light";
|
||||||
};
|
};
|
||||||
applyTheme();
|
applyTheme();
|
||||||
if (snapshot.locale && snapshot.locale !== locale) setLocale(snapshot.locale);
|
if (snapshot.locale && snapshot.locale !== locale) useAppStore.getState().setLocale(snapshot.locale);
|
||||||
if (snapshot.theme === "system") {
|
if (snapshot.theme === "system") {
|
||||||
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
const mq = window.matchMedia("(prefers-color-scheme: dark)");
|
||||||
mq.addEventListener("change", applyTheme);
|
mq.addEventListener("change", applyTheme);
|
||||||
return () => mq.removeEventListener("change", applyTheme);
|
return () => mq.removeEventListener("change", applyTheme);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- setLocale is a stable Zustand setter
|
|
||||||
}, [snapshot, locale]);
|
}, [snapshot, locale]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -87,9 +75,8 @@ export function useCompanyController() {
|
|||||||
// Keep selectedRunId in sync when run list changes
|
// Keep selectedRunId in sync when run list changes
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (selectedRunId && !companyData.runs.some((run) => run.id === selectedRunId)) {
|
if (selectedRunId && !companyData.runs.some((run) => run.id === selectedRunId)) {
|
||||||
setSelectedRunId(companyData.runs[0]?.id ?? null);
|
useAppStore.getState().setSelectedRunId(companyData.runs[0]?.id ?? null);
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- setSelectedRunId is a stable Zustand setter
|
|
||||||
}, [companyData.runs, selectedRunId]);
|
}, [companyData.runs, selectedRunId]);
|
||||||
|
|
||||||
// Pre-load run log when active run changes
|
// Pre-load run log when active run changes
|
||||||
@@ -105,47 +92,46 @@ export function useCompanyController() {
|
|||||||
incrementLogRevision();
|
incrementLogRevision();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setError(result.error.message);
|
useAppStore.getState().setError(result.error.message);
|
||||||
})();
|
})();
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- incrementLogRevision and setError are stable Zustand setters
|
}, [activeRunId, companyData.runs, incrementLogRevision]);
|
||||||
}, [activeRunId, companyData.runs]);
|
|
||||||
|
|
||||||
const setCompany = useCallback(async (companyId: string) => {
|
const setCompany = useCallback(async (companyId: string) => {
|
||||||
if (companyId === NEW_ENTITY_ID) { setShowOnboarding(true); return; }
|
const store = useAppStore.getState();
|
||||||
|
if (companyId === NEW_ENTITY_ID) { store.setShowOnboarding(true); return; }
|
||||||
try {
|
try {
|
||||||
unwrap(await window.agentCompany.setCurrentCompany(companyId));
|
unwrap(await window.agentCompany.setCurrentCompany(companyId));
|
||||||
clearCompanyScopedUiState();
|
clearCompanyScopedUiState();
|
||||||
await refresh();
|
await refresh();
|
||||||
setError(null);
|
store.setError(null);
|
||||||
} catch (err) { setError(err instanceof Error ? err.message : String(err)); }
|
} catch (err) { store.setError(err instanceof Error ? err.message : String(err)); }
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- setError and setShowOnboarding are stable Zustand setters
|
|
||||||
}, [clearCompanyScopedUiState, refresh]);
|
}, [clearCompanyScopedUiState, refresh]);
|
||||||
|
|
||||||
const deleteCompany = useCallback(async (companyId: string) => {
|
const deleteCompany = useCallback(async (companyId: string) => {
|
||||||
|
const store = useAppStore.getState();
|
||||||
try {
|
try {
|
||||||
unwrap(await window.agentCompany.deleteCompany(companyId));
|
unwrap(await window.agentCompany.deleteCompany(companyId));
|
||||||
setConfirmDeleteCompanyId(null);
|
store.setConfirmDeleteCompanyId(null);
|
||||||
setCompanySwitcherOpen(false);
|
store.setCompanySwitcherOpen(false);
|
||||||
await refresh();
|
await refresh();
|
||||||
} catch (err) { setError(err instanceof Error ? err.message : String(err)); }
|
} catch (err) { store.setError(err instanceof Error ? err.message : String(err)); }
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- Zustand setters are stable references
|
|
||||||
}, [refresh]);
|
}, [refresh]);
|
||||||
|
|
||||||
const handleOnboardingDone = useCallback(async (summary: OnboardingBootstrapResult) => {
|
const handleOnboardingDone = useCallback(async (summary: OnboardingBootstrapResult) => {
|
||||||
setShowOnboarding(false);
|
const store = useAppStore.getState();
|
||||||
setInitialOnboardingLocked(false);
|
store.setShowOnboarding(false);
|
||||||
|
store.setInitialOnboardingLocked(false);
|
||||||
await refresh();
|
await refresh();
|
||||||
setError(null);
|
store.setError(null);
|
||||||
setSection("overview");
|
store.setSection("overview");
|
||||||
if (summary.runId) setSelectedRunId(summary.runId);
|
if (summary.runId) store.setSelectedRunId(summary.runId);
|
||||||
if (summary.leadAgentId) setSelectedAgentId(summary.leadAgentId);
|
if (summary.leadAgentId) store.setSelectedAgentId(summary.leadAgentId);
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- Zustand setters are stable references
|
|
||||||
}, [refresh]);
|
}, [refresh]);
|
||||||
|
|
||||||
const openPathWithFeedback = useCallback(async (path: string) => {
|
const openPathWithFeedback = useCallback(async (path: string) => {
|
||||||
try { unwrap(await window.agentCompany.openPath(path)); setError(null); }
|
const store = useAppStore.getState();
|
||||||
catch (err) { setError(err instanceof Error ? err.message : String(err)); }
|
try { unwrap(await window.agentCompany.openPath(path)); store.setError(null); }
|
||||||
// eslint-disable-next-line react-hooks/exhaustive-deps -- setError is a stable Zustand setter
|
catch (err) { store.setError(err instanceof Error ? err.message : String(err)); }
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in new issue
Block a user