import { ActionIcon, Alert, Center, Code, Group, Pagination, Progress, Skeleton, Stack, Table, Text, Title, Tooltip, useMantineTheme, } from '@mantine/core'; import { useElementSize } from '@mantine/hooks'; 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 '../../hooks/widgets/dashDot/api'; import { humanFileSize } from '../../tools/humanFileSize'; dayjs.extend(duration); interface UsenetQueueListProps { appId: string; } const PAGE_SIZE = 13; export const UsenetQueueList: FunctionComponent = ({ appId }) => { const theme = useMantineTheme(); const { t } = useTranslation('modules/usenet'); const progressbarBreakpoint = parseInt(theme.breakpoints.xs, 10); const progressBreakpoint = 400; const sizeBreakpoint = 300; const { ref, width } = useElementSize(); const [page, setPage] = useState(1); const { data, isLoading, isError, error } = useGetUsenetDownloads({ limit: PAGE_SIZE, offset: (page - 1) * PAGE_SIZE, appId, }); const totalPages = Math.ceil((data?.total || 1) / PAGE_SIZE); if (isLoading) { return ( <> ); } if (isError) { return ( } my="lg" title={t('queue.error.title')} color="red" radius="md" > {t('queue.error.message')} {(error as AxiosError)?.response?.data as string} ); } if (!data || data.items.length <= 0) { return (
{t('queue.empty')}
); } // TODO: Set ScollArea dynamic height based on the widget size return ( {sizeBreakpoint < width ? ( ) : null} {progressBreakpoint < width ? ( ) : null} {data.items.map((nzb) => ( {sizeBreakpoint < width ? ( ) : null} {progressBreakpoint < width ? ( ) : null} ))}
{t('queue.header.name')}{t('queue.header.size')}{t('queue.header.eta')} width ? 100 : 200 }}> {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)}% {width > progressbarBreakpoint ? ( 0 ? theme.primaryColor : 'lightgrey'} value={nzb.progress} size="lg" style={{ width: '100%' }} /> ) : null}
{totalPages > 1 && ( )}
); };