import { NormalizedTorrent } from '@ctrl/shared-torrent'; import { Tooltip, Text, Progress, useMantineTheme } from '@mantine/core'; import { useElementSize } from '@mantine/hooks'; import { calculateETA } from '../../tools/calculateEta'; import { humanFileSize } from '../../tools/humanFileSize'; interface BitTorrentQueueItemProps { torrent: NormalizedTorrent; } export const BitTorrrentQueueItem = ({ torrent }: BitTorrentQueueItemProps) => { const MIN_WIDTH_MOBILE = useMantineTheme().breakpoints.xs; const { width } = useElementSize(); const downloadSpeed = torrent.downloadSpeed / 1024 / 1024; const uploadSpeed = torrent.uploadSpeed / 1024 / 1024; const size = torrent.totalSelected; return ( {torrent.name} {humanFileSize(size)} {width > MIN_WIDTH_MOBILE && ( {downloadSpeed > 0 ? `${downloadSpeed.toFixed(1)} Mb/s` : '-'} )} {width > MIN_WIDTH_MOBILE && ( {uploadSpeed > 0 ? `${uploadSpeed.toFixed(1)} Mb/s` : '-'} )} {width > MIN_WIDTH_MOBILE && ( {torrent.eta <= 0 ? '∞' : calculateETA(torrent.eta)} )} {(torrent.progress * 100).toFixed(1)}% ); };