import { useMemo, useState } from "react"; import { ArchiveX, Cloud, CloudDownload, Folder, Smartphone, Trash2 } from "lucide-react"; import { Button } from "@/components/ui/button.js"; import { cn } from "@/components/lib/utils.js"; import { ControlHintTooltip } from "@/ControlHintTooltip.js"; import { useConfirmDialog } from "@/hooks/useConfirmDialog.js"; import { useGlobalTaskList } from "@/hooks/useGlobalTaskList.js"; import { useBaseWorkspaceServices } from "@/hooks/useWorkspaceServices.js"; import { useZCodeIntl } from "@/i18n/IntlProvider.js"; import { formatTaskRelativeTime } from "@/lib/taskListItemPresentation.js"; import { getTaskChangeSummary } from "@/lib/taskChangeSummary.js"; import { getPathLeaf } from "@/lib/path.js"; import { logger } from "@/logger.js"; import { useRemoteWorkspaceSessionStore } from "@/store/remoteWorkspaceSessionStore.js"; import type { WorkspaceTabState } from "@/store/tabStore.js"; import { buildTaskWorkspaceKey } from "@/lib/taskQueryCache.js"; import { applyTaskQueryCacheMutation } from "@/store/taskQueryCacheStore.js"; import { removeTaskFromTaskCaches } from "@/lib/taskListMetaSync.js"; import { TaskListRemoteSyncHint } from "@/TaskListRemoteSyncHint.js"; import { TaskListLoadingHint } from "@/TaskListLoadingHint.js"; import { buildWorkspaceServiceLookup } from "@/lib/workspaceServiceResolver.js"; import { DeleteAllArchivedTasksButton } from "@/DeleteAllArchivedTasksButton.js"; export function WorkspaceArchivedTasksFlatSection({ workspaceTabs, activeWorkspacePath, activeWorkspaceIdentity, activeTaskId, sortBy, mobileActiveTaskKey, actionsContainer, onSelectTask, }: { workspaceTabs: WorkspaceTabState[]; activeWorkspacePath: string; activeWorkspaceIdentity?: string; activeTaskId: string | null; sortBy: "created" | "updated"; mobileActiveTaskKey?: string | null; actionsContainer?: HTMLElement | null; onSelectTask: ( targetWorkspacePath: string, taskId: string, targetWorkspaceIdentity?: string, ) => void; }) { const { intl } = useZCodeIntl(); const confirmDialog = useConfirmDialog(); const baseServices = useBaseWorkspaceServices(); const sessionsById = useRemoteWorkspaceSessionStore((state) => state.sessionsById); const sessionIdByWorkspaceIdentity = useRemoteWorkspaceSessionStore( (state) => state.sessionIdByWorkspaceIdentity, ); const sessionIdByWorkspacePath = useRemoteWorkspaceSessionStore( (state) => state.sessionIdByWorkspacePath, ); const serviceResolverState = useMemo( () => ({ sessionsById, sessionIdByWorkspaceIdentity, sessionIdByWorkspacePath, }), [sessionIdByWorkspaceIdentity, sessionIdByWorkspacePath, sessionsById], ); const [showAllTasks, setShowAllTasks] = useState(false); const [deletingTaskKeys, setDeletingTaskKeys] = useState>(() => new Set()); const collapsedLimit = 20; const workspaceLabelByKey = useMemo( () => new Map( workspaceTabs.map( (tab) => [ buildTaskWorkspaceKey(tab.workspacePath, tab.workspaceIdentity), tab.label || getPathLeaf(tab.workspacePath), ] as const, ), ), [workspaceTabs], ); const workspaceServiceLookup = useMemo( () => buildWorkspaceServiceLookup(workspaceTabs, baseServices, serviceResolverState), [baseServices, serviceResolverState, workspaceTabs], ); const activeWorkspaceKey = buildTaskWorkspaceKey(activeWorkspacePath, activeWorkspaceIdentity); const { items, total, loading, syncingRemoteWorkspaces, refresh } = useGlobalTaskList({ kind: "archived", workspaceTabs, sortBy, searchQuery: "", expanded: showAllTasks, collapsedLimit, }); const canToggleExpanded = total > collapsedLimit; return (
({ workspacePath: tab.workspacePath, workspaceIdentity: tab.workspaceIdentity, label: tab.label || getPathLeaf(tab.workspacePath), service: workspaceServiceLookup.get( buildTaskWorkspaceKey(tab.workspacePath, tab.workspaceIdentity), )?.services.zcodeTaskService, }))} onDeleted={removeTaskFromTaskCaches} onRefresh={refresh} /> {items.length === 0 ? ( loading ? ( ) : (
{intl.formatMessage({ id: "taskList.noArchivedTasks" })}
) ) : null}
    {items.map((task) => { const workspaceServices = workspaceServiceLookup.get( buildTaskWorkspaceKey(task.workspacePath, task.workspaceIdentity), ); if (!workspaceServices) { return null; } const { services } = workspaceServices; const taskTitle = task.title || intl.formatMessage({ id: "taskList.untitled" }); const taskTimeLabel = formatTaskRelativeTime( sortBy === "created" ? task.createdAt : task.updatedAt, intl, ); const taskChangeSummary = getTaskChangeSummary(task); const workspaceKey = buildTaskWorkspaceKey(task.workspacePath, task.workspaceIdentity); const workspaceLabel = workspaceLabelByKey.get(workspaceKey) ?? getPathLeaf(task.workspacePath); const isRemoteTask = Boolean(task.workspaceIdentity?.trim()); const unarchiveLabel = intl.formatMessage({ id: "taskList.unarchive" }); const deleteLabel = intl.formatMessage({ id: "taskList.delete" }); // archived 平铺列表同样是跨 workspace 视图,选中态要按 workspaceKey 隔离。 const isActive = workspaceKey === activeWorkspaceKey && task.taskId === activeTaskId; const isMobileActive = mobileActiveTaskKey === `${workspaceKey}:${task.taskId}`; const taskKey = `${workspaceKey}:${task.taskId}`; const isDeleting = deletingTaskKeys.has(taskKey); return (
  • { onSelectTask(task.workspacePath, task.taskId, task.workspaceIdentity); }} className={cn( "cursor-pointer rounded-lg px-2.5 py-2 transition-[background-color,border-color,box-shadow]", isActive ? "bg-selected" : "hover:bg-surface-hover", )} >
    {isMobileActive ? ( {/* Bugfix: 归档视图也可能保留手机端当前 task 的旧状态,展示同一标记避免列表间状态不一致。 上一版把标记放进标题行 flex 流里,会让只有手机标记的 task 标题右移; 这里用绝对定位放在标题左侧,让标题文本继续按原始位置对齐。 */} ) : null}

    {taskTitle}

    {taskTimeLabel}
    {/* Bugfix: archived 列表以前本地和远端任务都显示 Folder, 用户无法判断取消归档会作用在哪一侧。这里用 Cloud 区分远端来源。 */} {isRemoteTask ? ( ) : ( )} {workspaceLabel} {taskChangeSummary ? ( {intl.formatMessage( { id: "taskList.changeStats" }, { added: String(taskChangeSummary.added), removed: String(taskChangeSummary.removed), }, )} ) : null} {/* Bugfix:删除请求期间 button 会 disabled,disabled 元素不产生 hover 事件; 用真实 span 承接 tooltip trigger,保持处理中仍能解释该 action。 */}
  • ); })}
{syncingRemoteWorkspaces ? : null} {canToggleExpanded ? (
{ setShowAllTasks((current) => !current); }} > {intl.formatMessage({ id: showAllTasks ? "taskList.showLess" : "taskList.showMore", })}
) : null}
); }