"use client"; import { useState } from "react"; import { Button } from "yt-dlp-transcript-common/components/ui/button"; import type { AutoQueueKind } from "yt-dlp-transcript-common/jobs/autoQueueState"; import { snoozeAutoQueueAction } from "../actions"; import { snoozePresets } from "./dispatch"; // Idle a runner for a while without stopping it. // // The distinction matters operationally: stopping loses the in-flight work and // needs someone to remember to start it again, whereas a snooze leaves the loop // up, re-reading settings every iteration, so it resumes by itself. And because // the deadline is persisted in settings.json rather than held in runner memory, // it survives a server restart — which a "pause" flag in the process would not. export function SnoozeControl({ kind, title, snoozeUntil, now, onChanged, }: { kind: AutoQueueKind; title: string; snoozeUntil: number | null; now: number | null; onChanged: () => Promise; }) { const [busy, setBusy] = useState(false); const snoozed = snoozeUntil !== null && (now === null || snoozeUntil > now); const set = async (until: number | null) => { setBusy(true); try { await snoozeAutoQueueAction(kind, until); await onChanged(); } finally { setBusy(false); } }; if (snoozed) { return (
Snoozed until{" "} {new Date(snoozeUntil).toLocaleString([], { hour: "2-digit", minute: "2-digit", month: "short", day: "numeric", })} {" — the runner stays up and resumes by itself."}
); } return (
Snooze {snoozePresets(now ?? Date.now()).map((p) => ( ))}
); }