"use client"; import { useMemo, useState, memo } from "react"; import { IconPlus } from "@tabler/icons-react"; import { Sheet, SheetContent, SheetHeader, SheetTitle } from "@kandev/ui/sheet"; import { Button } from "@kandev/ui/button"; import { TaskSwitcher } from "../task-switcher"; import type { TaskSwitcherItem } from "../task-switcher"; import type { StepDef } from "../task-switcher-context-menu"; import type { TaskMoveWorkflow } from "../task-move-context-menu"; import { applyView } from "@/lib/sidebar/apply-view"; import { useEffectiveSidebarView } from "@/hooks/domains/sidebar/use-effective-sidebar-view"; import { useSidebarTaskPrefs } from "@/hooks/domains/sidebar/use-sidebar-task-prefs"; import { WorkspaceSwitcher } from "../workspace-switcher"; import { TaskCreateDialog } from "@/components/task-create-dialog"; import { TaskArchiveConfirmDialog } from "../task-archive-confirm-dialog"; import { TaskDeleteConfirmDialog } from "../task-delete-confirm-dialog"; import { useSheetData, useSheetActions } from "./session-task-switcher-sheet-hooks"; type SessionTaskSwitcherSheetProps = { open: boolean; onOpenChange: (open: boolean) => void; workspaceId: string | null; workflowId: string | null; }; function MobileTaskList({ tasks, workflows, stepsByWorkflowId, activeTaskId, selectedTaskId, onSelectTask, onArchiveTask, onDeleteTask, deletingTaskId, isLoading, }: { tasks: TaskSwitcherItem[]; workflows: TaskMoveWorkflow[]; stepsByWorkflowId: Record; activeTaskId: string | null; selectedTaskId: string | null; onSelectTask: (taskId: string) => void; onArchiveTask: (taskId: string) => void; onDeleteTask: (taskId: string) => Promise | void; deletingTaskId: string | null; isLoading?: boolean; }) { const view = useEffectiveSidebarView(); const { pinnedTaskIds, orderedTaskIds, subtaskOrderByParentId, togglePinnedTask, handleReorderGroup, handleReorderSubtasks, } = useSidebarTaskPrefs(); const grouped = useMemo( () => applyView(tasks, view, { pinnedTaskIds, orderedTaskIds, subtaskOrderByParentId, }), [tasks, view, pinnedTaskIds, orderedTaskIds, subtaskOrderByParentId], ); return ( ); } export const SessionTaskSwitcherSheet = memo(function SessionTaskSwitcherSheet({ open, onOpenChange, workspaceId, workflowId, }: SessionTaskSwitcherSheetProps) { const [dialogOpen, setDialogOpen] = useState(false); const data = useSheetData(workspaceId); const actions = useSheetActions(workspaceId, onOpenChange); return (
Tasks
({ id: w.id, name: w.name }))} activeWorkspaceId={workspaceId} onSelect={actions.handleWorkspaceChange} />
{ if (!open) actions.setArchivingTask(null); }} taskTitle={actions.archivingTask?.title ?? ""} taskId={actions.archivingTask?.id} executorType={actions.archivingTask?.executorType} isArchiving={actions.isArchiving} onConfirm={({ cascade }) => actions.handleArchiveConfirm({ cascade })} /> { if (!open) actions.setDeletingTask(null); }} taskTitle={actions.deletingTask?.title ?? ""} taskId={actions.deletingTask?.id} executorType={actions.deletingTask?.executorType} isDeleting={actions.isDeleting} onConfirm={({ cascade }) => actions.handleDeleteConfirm({ cascade })} />
); });