/* eslint-disable @next/next/no-img-element */
import { NormalizedTorrent } from '@ctrl/shared-torrent';
import {
Badge,
Divider,
Flex,
Group,
List,
MantineColor,
Popover,
Progress,
Stack,
Text,
Title,
useMantineTheme,
} from '@mantine/core';
import { useDisclosure, useElementSize } from '@mantine/hooks';
import {
IconAffiliate,
IconDatabase,
IconDownload,
IconInfoCircle,
IconPercentage,
IconSortDescending,
IconUpload,
} from '@tabler/icons';
import { useTranslation } from 'next-i18next';
import { calculateETA } from '../../tools/calculateEta';
import { humanFileSize } from '../../tools/humanFileSize';
import { AppType } from '../../types/app';
interface TorrentQueueItemProps {
torrent: NormalizedTorrent;
app?: AppType;
}
export const BitTorrrentQueueItem = ({ torrent, app }: TorrentQueueItemProps) => {
const [popoverOpened, { open: openPopover, close: closePopover }] = useDisclosure(false);
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}
{app && (
Managed by {app.name}, {torrent.ratio.toFixed(2)} ratio
)}
|
{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)}%
|
);
};
const TorrentQueuePopover = ({ torrent, app }: TorrentQueueItemProps) => {
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 (
Ratio -
{torrent.ratio.toFixed(2)}
);
};
return (
{app && (
{t('card.popover.introductionPrefix')}
{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),
})}
}>
{humanFileSize(torrent.totalDownloaded)}
{humanFileSize(torrent.totalUploaded)}
}>
{t('card.popover.metrics.state', {
state: torrent.stateMessage !== '' ? torrent.stateMessage : torrent.state,
})}
{(torrent.label || torrent.isCompleted) && (
{torrent.label && {torrent.label}}
{torrent.isCompleted && (
{t('card.popover.metrics.completed')}
)}
)}
);
};