import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query"; import { Database, Loader2, Pause, Play } from "lucide-react"; import { api } from "../lib/api"; import { formatViews } from "../lib/format"; // Per-user status (not the global catalog): shows the number of videos available to *this* // user and how many of *their* channels are still being fetched. The pause control is // admin-only (it pauses the shared background sync). export default function SyncStatus({ isAdmin }: { isAdmin: boolean }) { 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; return (