Files
fusion/packages/dashboard/app/hooks/useMainPanelTaskDetail.ts
gsxdsm f6f9e822f5 refactor(dashboard): extract task-detail, board-scroll, popped-out hooks
Extract three AppInner state clusters into hooks:
- useMainPanelTaskDetail: the main-panel task-detail snapshot + initial tab;
  setTask accepts the SetStateAction updater form so the embedded detail can
  patch the snapshot on task updates.
- useBoardScrollRestore: the board scroll snapshot refs, capture, and the
  double-requestAnimationFrame restore effect keyed on taskView; exposes
  requestRestore for App to schedule a restore on detail close.
- usePoppedOutTasks: the popped-out task-detail windows (dedupe-by-id popOut,
  close-by-id).

App keeps the navigation-history composition (openTaskDetailInMainPanel /
closeTaskDetailMainPanel) and now consumes the hooks' primitives.
Behavior-preserving; App.test.tsx identical (5 pre-existing failures, none
introduced). Verified by typecheck, eslint, and 5 renderHook tests.

Completes U6 (App.tsx module-breakup plan).
2026-06-23 21:09:36 -07:00

23 lines
1.1 KiB
TypeScript

/*
FNXC:TaskDetail 2026-06-24-00:00:
Snapshot of the task whose detail is shown in the main panel (Board card click → full-panel detail), plus its initial tab. Kept as a snapshot so the view survives a tasks revalidation. Exposes the setters so App can compose open/close with view navigation, and so the embedded detail can patch the snapshot on task updates (setTask accepts the updater form). Extracted from AppInner.
*/
import { useState, type Dispatch, type SetStateAction } from "react";
import type { Task, TaskDetail } from "@fusion/core";
import type { DetailTaskTab } from "./useModalManager";
export interface UseMainPanelTaskDetailResult {
task: Task | TaskDetail | null;
initialTab: DetailTaskTab;
setTask: Dispatch<SetStateAction<Task | TaskDetail | null>>;
setInitialTab: (tab: DetailTaskTab) => void;
}
export function useMainPanelTaskDetail(): UseMainPanelTaskDetailResult {
const [task, setTask] = useState<Task | TaskDetail | null>(null);
const [initialTab, setInitialTab] = useState<DetailTaskTab>("chat");
return { task, initialTab, setTask, setInitialTab };
}