import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { Database, History, Loader2, Pause, Play } from "lucide-react"; import { api } from "../lib/api"; import { formatViews } from "../lib/format"; import Tooltip from "./Tooltip"; // Per-user status (not the global catalog): shows the number of videos available to *this* // user, how many of *their* channels are still being fetched, and how many lack full // history (clickable -> channel manager filtered to those). The pause control is admin-only. export default function SyncStatus({ isAdmin, onGoToFullHistory, }: { isAdmin: boolean; onGoToFullHistory: () => void; }) { const qc = useQueryClient(); const { data } = useQuery({ queryKey: ["my-status"], queryFn: api.myStatus, refetchInterval: 30_000, staleTime: 25_000, }); const toggle = useMutation({ mutationFn: () => (data?.paused ? api.resumeSync() : api.pauseSync()), onSuccess: () => qc.invalidateQueries({ queryKey: ["my-status"] }), }); if (!data) return null; const syncing = data.channels_recent_pending; const notFull = data.channels_deep_pending; // your channels without full history yet return (
{formatViews(data.my_videos)} yours / {formatViews(data.total_videos)} total · {data.paused ? ( paused ) : syncing > 0 ? ( {syncing} syncing ) : ( all synced )} {notFull > 0 && ( <> · )} {/* Pause only makes sense when there's work to pause; Resume must always show while paused so it can be lifted. Hidden entirely when idle and not paused. */} {isAdmin && (data.paused || syncing > 0) && ( )}
); }