import { ActionIcon, Alert, Center, Code, Group, Pagination, Progress, Skeleton, Table, Text, Title, Tooltip, useMantineTheme, } from '@mantine/core'; import { IconAlertCircle, IconPlayerPause, IconPlayerPlay } from '@tabler/icons'; import { AxiosError } from 'axios'; import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration'; import { useTranslation } from 'next-i18next'; import { FunctionComponent, useState } from 'react'; import { useGetUsenetDownloads } from '../../tools/hooks/api'; import { humanFileSize } from '../../tools/humanFileSize'; dayjs.extend(duration); interface UsenetQueueListProps { serviceId: string; } const PAGE_SIZE = 10; export const UsenetQueueList: FunctionComponent = ({ serviceId }) => { const theme = useMantineTheme(); const { t } = useTranslation('modules/usenet'); const [page, setPage] = useState(1); const { data, isLoading, isError, error } = useGetUsenetDownloads({ limit: PAGE_SIZE, offset: (page - 1) * PAGE_SIZE, serviceId, }); const totalPages = Math.ceil((data?.total || 1) / PAGE_SIZE); if (isLoading) { return ( <> ); } if (isError) { return ( } my="lg" title="Error!" color="red" radius="md"> {t('queue.error')} {(error as AxiosError)?.response?.data as string} ); } if (!data || data.items.length <= 0) { return (
{t('queue.empty')}
); } return ( <> {data.items.map((nzb) => ( ))}
{t('queue.header.name')} {t('queue.header.size')} {t('queue.header.eta')} {t('queue.header.progress')}
{nzb.state === 'paused' ? ( ) : ( )} {nzb.name} {humanFileSize(nzb.size)} {nzb.eta <= 0 ? ( {t('queue.paused')} ) : ( {dayjs.duration(nzb.eta, 's').format('H:mm:ss')} )} {nzb.progress.toFixed(1)}% 0 ? theme.primaryColor : 'lightgrey'} value={nzb.progress} size="lg" style={{ width: '100%' }} />
{totalPages > 1 && ( )} ); };