The best way to control Claude Code, Codex and more from any computer or phone

main
ts 24 lines 1.11 KB
Raw
1 import { useState } from "react";
2
3 import { useNowAfter, useNowMinuteMs } from "../../lib/clock";
4 import { nextSnoozeWakeAfter } from "./threadListV2";
5
6 /**
7 * The thread list's clock as an ISO timestamp. It advances on each wall-clock
8 * minute and the moment any snooze expires, so the list re-partitions on time
9 * instead of on the next minute tick. Waking on every snoozed thread, not just
10 * the ones the list shows as snoozed, only costs an extra render.
11 */
12 export function useThreadListNow(
13 threads: ReadonlyArray<{ readonly snoozedUntil?: string | null }>,
14 ): string {
15 const minuteMs = useNowMinuteMs();
16 // The latest time returned. The next wake is searched after it, not after
17 // the floored minute, so a second snooze expiring later in the same minute
18 // arms its own wake instead of waiting for the next minute tick.
19 const [latestMs, setLatestMs] = useState(minuteMs);
20 const afterWakeMs = useNowAfter(nextSnoozeWakeAfter(threads, Math.max(minuteMs, latestMs)));
21 const nowMs = Math.max(minuteMs, afterWakeMs, latestMs);
22 if (nowMs !== latestMs) setLatestMs(nowMs);
23 return new Date(nowMs).toISOString();
24 }