import { useCallback, useEffect, useRef, useState } from "react"; import { getKey } from "../api/client"; import { useCatalog } from "./useCatalog"; import { useTaskList } from "./useTaskList"; import { useTaskDetail } from "./useTaskDetail"; import { useProjectTools } from "./useProjectTools"; import { formatRefreshTime } from "./useAutoRefresh"; import type { ConsoleCtx } from "../context"; // Glue only: composes the domain hooks into one ConsoleCtx and owns // the auto-refresh policy. No API calls and no rendering live here. export function useConsoleStore(): ConsoleCtx { const catalog = useCatalog(); const taskList = useTaskList(); const projectIdRef = useRef(""); projectIdRef.current = catalog.projectId; const getProjectId = useCallback(() => projectIdRef.current, []); const tools = useProjectTools(getProjectId); const getRole = useCallback((pid?: string) => { const p = catalog.projects.find((x) => x.id === pid); return p ? (p.my_role || null) : null; }, [catalog.projects]); const onTasksReload = useCallback(() => { void taskList.refreshTasks(undefined, projectIdRef.current); }, [taskList]); const detail = useTaskDetail(getRole, onTasksReload); const [refreshStamp, setRefreshStamp] = useState("--:--:--"); const selectProject = useCallback((id: string) => { catalog.setProjectId(id); projectIdRef.current = id; void taskList.refreshTasks(id); void catalog.refreshEnvs(id); void catalog.refreshMembers(id); void catalog.refreshSkills(id); void tools.refreshAutomations(id); void tools.refreshTriage(id); }, [catalog, taskList, tools]); // Fix: the old single page's project