import { Progress } from "@/components/ui/progress"; import prettyBytes from "pretty-bytes"; import { type TelegramFile } from "@/lib/types"; import { useFileSpeed } from "@/hooks/use-file-speed"; import { useMemo } from "react"; import { ClockArrowDown, Zap } from "lucide-react"; export default function FileProgress({ file }: { file: TelegramFile }) { const { downloadProgress, downloadSpeed } = useFileSpeed(file.id); const progress = useMemo(() => { const fileDownloadProgress = file.size > 0 ? Math.min((file.downloadedSize / file.size) * 100, 100) : 0; if (file.downloadStatus === "downloading") { return downloadProgress > 0 ? downloadProgress : fileDownloadProgress; } if (file.downloadStatus === "paused") { return fileDownloadProgress; } return file.downloadStatus === "completed" ? 100 : 0; }, [file.downloadStatus, file.downloadedSize, file.size, downloadProgress]); if (file.downloadStatus === "idle" || file.downloadStatus === "completed" || file.size === 0) { return null; } return (