({
tasks,
isStandalone = false
}: Props)
| 28 | return a.id.localeCompare(b.id); |
| 29 | } |
| 30 | export function TaskListV2({ |
| 31 | tasks, |
| 32 | isStandalone = false |
| 33 | }: Props): React.ReactNode { |
| 34 | const teamContext = useAppState(s => s.teamContext); |
| 35 | const appStateTasks = useAppState(s_0 => s_0.tasks); |
| 36 | const [, forceUpdate] = React.useState(0); |
| 37 | const { |
| 38 | rows, |
| 39 | columns |
| 40 | } = useTerminalSize(); |
| 41 | |
| 42 | // Track when each task was last observed transitioning to completed |
| 43 | const completionTimestampsRef = React.useRef(new Map<string, number>()); |
| 44 | const previousCompletedIdsRef = React.useRef<Set<string> | null>(null); |
| 45 | if (previousCompletedIdsRef.current === null) { |
| 46 | previousCompletedIdsRef.current = new Set(tasks.filter(t => t.status === 'completed').map(t_0 => t_0.id)); |
| 47 | } |
| 48 | const maxDisplay = rows <= 10 ? 0 : Math.min(10, Math.max(3, rows - 14)); |
| 49 | |
| 50 | // Update completion timestamps: reset when a task transitions to completed |
| 51 | const currentCompletedIds = new Set(tasks.filter(t_1 => t_1.status === 'completed').map(t_2 => t_2.id)); |
| 52 | const now = Date.now(); |
| 53 | for (const id of currentCompletedIds) { |
| 54 | if (!previousCompletedIdsRef.current.has(id)) { |
| 55 | completionTimestampsRef.current.set(id, now); |
| 56 | } |
| 57 | } |
| 58 | for (const id_0 of completionTimestampsRef.current.keys()) { |
| 59 | if (!currentCompletedIds.has(id_0)) { |
| 60 | completionTimestampsRef.current.delete(id_0); |
| 61 | } |
| 62 | } |
| 63 | previousCompletedIdsRef.current = currentCompletedIds; |
| 64 | |
| 65 | // Schedule re-render when the next recent completion expires. |
| 66 | // Depend on `tasks` so the timer is only reset when the task list changes, |
| 67 | // not on every render (which was causing unnecessary work). |
| 68 | React.useEffect(() => { |
| 69 | if (completionTimestampsRef.current.size === 0) { |
| 70 | return; |
| 71 | } |
| 72 | const currentNow = Date.now(); |
| 73 | let earliestExpiry = Infinity; |
| 74 | for (const ts of completionTimestampsRef.current.values()) { |
| 75 | const expiry = ts + RECENT_COMPLETED_TTL_MS; |
| 76 | if (expiry > currentNow && expiry < earliestExpiry) { |
| 77 | earliestExpiry = expiry; |
| 78 | } |
| 79 | } |
| 80 | if (earliestExpiry === Infinity) { |
| 81 | return; |
| 82 | } |
| 83 | const timer = setTimeout(forceUpdate_0 => forceUpdate_0((n: number) => n + 1), earliestExpiry - currentNow, forceUpdate); |
| 84 | return () => clearTimeout(timer); |
| 85 | }, [tasks]); |
| 86 | if (!isTodoV2Enabled()) { |
| 87 | return null; |
nothing calls this directly
no test coverage detected