- Extract view state, project actions, and task handler concerns from AppInner into dedicated hooks - Add AppModals component to centralize modal rendering and related props wiring - Inline thin aliases and complete AppInner cleanup after moving responsibilities out - Add unit tests for useViewState, useProjectActions, and useTaskHandlers hooks
71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
import { useCallback } from "react";
|
|
import type { Task, TaskCreateInput } from "@fusion/core";
|
|
import type { ToastType } from "./useToast";
|
|
|
|
interface UseTaskHandlersOptions {
|
|
createTask: (input: TaskCreateInput) => Promise<Task>;
|
|
onPlanningTaskCreated: (task: Task, addToast: (msg: string, type?: ToastType) => void) => void;
|
|
onPlanningTasksCreated: (tasks: Task[], addToast: (msg: string, type?: ToastType) => void) => void;
|
|
onSubtaskTasksCreated: (tasks: Task[], addToast: (msg: string, type?: ToastType) => void) => void;
|
|
addToast: (message: string, type?: ToastType) => void;
|
|
}
|
|
|
|
export interface UseTaskHandlersResult {
|
|
handleBoardQuickCreate: (input: TaskCreateInput) => Promise<void>;
|
|
handleModalCreate: (input: TaskCreateInput) => Promise<Task>;
|
|
handlePlanningTaskCreated: (task: Task) => void;
|
|
handlePlanningTasksCreated: (tasks: Task[]) => void;
|
|
handleSubtaskTasksCreated: (tasks: Task[]) => void;
|
|
handleGitHubImport: (task: Task) => void;
|
|
}
|
|
|
|
export function useTaskHandlers(options: UseTaskHandlersOptions): UseTaskHandlersResult {
|
|
const {
|
|
createTask,
|
|
onPlanningTaskCreated,
|
|
onPlanningTasksCreated,
|
|
onSubtaskTasksCreated,
|
|
addToast,
|
|
} = options;
|
|
|
|
const handleBoardQuickCreate = useCallback(
|
|
async (input: TaskCreateInput): Promise<void> => {
|
|
await createTask({ ...input, column: "triage" });
|
|
},
|
|
[createTask],
|
|
);
|
|
|
|
const handleModalCreate = useCallback(
|
|
async (input: TaskCreateInput): Promise<Task> => {
|
|
const task = await createTask({ ...input, column: "triage" });
|
|
return task;
|
|
},
|
|
[createTask],
|
|
);
|
|
|
|
const handlePlanningTaskCreated = useCallback((task: Task) => {
|
|
onPlanningTaskCreated(task, addToast);
|
|
}, [onPlanningTaskCreated, addToast]);
|
|
|
|
const handlePlanningTasksCreated = useCallback((tasks: Task[]) => {
|
|
onPlanningTasksCreated(tasks, addToast);
|
|
}, [onPlanningTasksCreated, addToast]);
|
|
|
|
const handleSubtaskTasksCreated = useCallback((tasks: Task[]) => {
|
|
onSubtaskTasksCreated(tasks, addToast);
|
|
}, [onSubtaskTasksCreated, addToast]);
|
|
|
|
const handleGitHubImport = useCallback((task: Task) => {
|
|
addToast(`Imported ${task.id} from GitHub`, "success");
|
|
}, [addToast]);
|
|
|
|
return {
|
|
handleBoardQuickCreate,
|
|
handleModalCreate,
|
|
handlePlanningTaskCreated,
|
|
handlePlanningTasksCreated,
|
|
handleSubtaskTasksCreated,
|
|
handleGitHubImport,
|
|
};
|
|
}
|