import {
Badge,
Center,
Flex,
Group,
Loader,
ScrollArea,
Stack,
Table,
Text,
Title,
useMantineTheme,
} from '@mantine/core';
import { useElementSize } from '@mantine/hooks';
import { IconFileDownload } from '@tabler/icons';
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import relativeTime from 'dayjs/plugin/relativeTime';
import { useTranslation } from 'next-i18next';
import { useGetDownloadClientsQueue } from '../../hooks/widgets/download-speed/useGetNetworkSpeed';
import { NormalizedDownloadQueueResponse } from '../../types/api/downloads/queue/NormalizedDownloadQueueResponse';
import { AppIntegrationType } from '../../types/app';
import { defineWidget } from '../helper';
import { IWidget } from '../widgets';
import { BitTorrrentQueueItem } from './TorrentQueueItem';
dayjs.extend(duration);
dayjs.extend(relativeTime);
const downloadAppTypes: AppIntegrationType['type'][] = ['deluge', 'qBittorrent', 'transmission'];
const definition = defineWidget({
id: 'torrents-status',
icon: IconFileDownload,
options: {
displayCompletedTorrents: {
type: 'switch',
defaultValue: true,
},
displayStaleTorrents: {
type: 'switch',
defaultValue: true,
},
},
gridstack: {
minWidth: 2,
minHeight: 2,
maxWidth: 12,
maxHeight: 14,
},
component: TorrentTile,
});
export type ITorrent = IWidget<(typeof definition)['id'], typeof definition>;
interface TorrentTileProps {
widget: ITorrent;
}
function TorrentTile({ widget }: TorrentTileProps) {
const { t } = useTranslation('modules/torrents-status');
const MIN_WIDTH_MOBILE = useMantineTheme().breakpoints.xs;
const { width } = useElementSize();
const {
data,
isError,
isInitialLoading,
dataUpdatedAt,
}: {
data: NormalizedDownloadQueueResponse | undefined;
isError: boolean;
isInitialLoading: boolean;
dataUpdatedAt: number;
} = useGetDownloadClientsQueue();
if (isError) {
return (
| {t('card.table.header.name')} | {t('card.table.header.size')} | {width > MIN_WIDTH_MOBILE &&{t('card.table.header.download')} | } {width > MIN_WIDTH_MOBILE &&{t('card.table.header.upload')} | } {width > MIN_WIDTH_MOBILE &&{t('card.table.header.estimatedTimeOfArrival')} | }{t('card.table.header.progress')} |
|---|