/* eslint-disable @next/next/no-img-element */ import { NormalizedTorrent } from '@ctrl/shared-torrent'; import { Badge, Flex, Group, List, MantineColor, Popover, Progress, Stack, Text, createStyles, useMantineTheme, } from '@mantine/core'; import { IconAffiliate, IconDatabase, IconDownload, IconFileInfo, IconInfoCircle, IconPercentage, IconSortDescending, IconUpload, } from '@tabler/icons-react'; import { useTranslation } from 'next-i18next'; import { MIN_WIDTH_MOBILE } from '~/constants/constants'; import { calculateETA } from '~/tools/client/calculateEta'; import { humanFileSize } from '~/tools/humanFileSize'; import { AppType } from '~/types/app'; interface TorrentQueueItemProps { torrent: NormalizedTorrent; app?: AppType; width: number; } export const BitTorrentQueueItem = ({ torrent, width, app }: TorrentQueueItemProps) => { const { classes } = useStyles(); const { t } = useTranslation('modules/torrents-status'); const downloadSpeed = torrent.downloadSpeed / 1024 / 1024; const uploadSpeed = torrent.uploadSpeed / 1024 / 1024; const size = torrent.totalSelected; return ( {torrent.name} {app && ( {t('card.table.item.text', { appName: app.name, ratio: torrent.ratio.toFixed(2), })} )} {humanFileSize(size, false)} {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)}% ); }; const TorrentQueuePopover = ({ torrent, app }: Omit) => { const { t } = useTranslation('modules/torrents-status'); const { colors } = useMantineTheme(); const RatioMetric = () => { const color = (): MantineColor => { if (torrent.ratio < 1) { return colors.red[7]; } if (torrent.ratio < 1.15) { return colors.orange[7]; } return colors.green[7]; }; return ( {t('card.popover.metrics.ratio')} {torrent.ratio.toFixed(2)} ); }; return ( {app && ( {t('card.popover.introductionPrefix')} download client logo {app.name} )} }> {torrent.name} }> }> {t('card.popover.metrics.queuePosition', { position: torrent.queuePosition })} }> {t('card.popover.metrics.progress', { progress: (torrent.progress * 100).toFixed(2), })} }> {t('card.popover.metrics.totalSelectedSize', { totalSize: humanFileSize(torrent.totalSelected, false), })} }> {humanFileSize(torrent.totalDownloaded, false)} {humanFileSize(torrent.totalUploaded, false)} }> {t('card.popover.metrics.state', { state: torrent.stateMessage !== '' ? torrent.stateMessage : torrent.state, })} {torrent.label && {torrent.label}} {torrent.isCompleted && ( {t('card.popover.metrics.completed')} )} ); }; const useStyles = createStyles(() => ({ noTextBreak: { whiteSpace: 'nowrap', }, }));