import { useEffect, useState } from "react"; import { Button } from "@/components/ui/button"; import { Loader2, Pause } from "lucide-react"; interface RefreshLoopProps { onRefresh: () => void; isPaused?: boolean; isLoading: boolean; className?: string; } export function RefreshLoop({ onRefresh, isPaused = false, isLoading, className, }: RefreshLoopProps) { const [delayedLoading, setDelayedLoading] = useState(isLoading); useEffect(() => { let timeoutId: NodeJS.Timeout; if (isLoading) { setDelayedLoading(true); } else { timeoutId = setTimeout(() => { setDelayedLoading(false); }, 1000); // Keep loading state for 1 second after isLoading becomes false } return () => { if (timeoutId) clearTimeout(timeoutId); }; }, [isLoading]); return (
{isPaused ? ( ) : ( )} {isPaused ? "Auto-refresh paused" : delayedLoading ? "Refreshing..." : ``}
); }