2022-12-11 16:06:41 +01:00
|
|
|
import {
|
|
|
|
|
ActionIcon,
|
|
|
|
|
Alert,
|
|
|
|
|
Center,
|
|
|
|
|
Code,
|
|
|
|
|
Group,
|
|
|
|
|
Pagination,
|
|
|
|
|
Progress,
|
|
|
|
|
Skeleton,
|
2023-01-06 13:39:45 +09:00
|
|
|
Stack,
|
2022-12-11 16:06:41 +01:00
|
|
|
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';
|
2022-12-31 16:07:05 +01:00
|
|
|
import { useGetUsenetDownloads } from '../../hooks/widgets/dashDot/api';
|
2022-12-16 21:01:06 +01:00
|
|
|
import { humanFileSize } from '../../tools/humanFileSize';
|
2022-12-11 16:06:41 +01:00
|
|
|
|
|
|
|
|
dayjs.extend(duration);
|
|
|
|
|
|
|
|
|
|
interface UsenetQueueListProps {
|
2022-12-18 22:27:01 +01:00
|
|
|
appId: string;
|
2022-12-11 16:06:41 +01:00
|
|
|
}
|
|
|
|
|
|
2023-01-06 13:39:45 +09:00
|
|
|
const PAGE_SIZE = 13;
|
2022-12-11 16:06:41 +01:00
|
|
|
|
2022-12-18 22:27:01 +01:00
|
|
|
export const UsenetQueueList: FunctionComponent<UsenetQueueListProps> = ({ appId }) => {
|
2022-12-11 16:06:41 +01:00
|
|
|
const theme = useMantineTheme();
|
|
|
|
|
const { t } = useTranslation('modules/usenet');
|
2023-03-03 00:37:22 +09:00
|
|
|
const progressbarBreakpoint = parseInt(theme.breakpoints.xs, 10);
|
2022-12-11 16:06:41 +01:00
|
|
|
const progressBreakpoint = 400;
|
|
|
|
|
const sizeBreakpoint = 300;
|
2023-01-06 13:39:45 +09:00
|
|
|
const { ref, width } = useElementSize();
|
2022-12-11 16:06:41 +01:00
|
|
|
|
|
|
|
|
const [page, setPage] = useState(1);
|
|
|
|
|
const { data, isLoading, isError, error } = useGetUsenetDownloads({
|
|
|
|
|
limit: PAGE_SIZE,
|
|
|
|
|
offset: (page - 1) * PAGE_SIZE,
|
2023-01-05 22:42:56 +09:00
|
|
|
appId,
|
2022-12-11 16:06:41 +01:00
|
|
|
});
|
|
|
|
|
const totalPages = Math.ceil((data?.total || 1) / PAGE_SIZE);
|
|
|
|
|
|
|
|
|
|
if (isLoading) {
|
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<Skeleton height={40} mt={10} />
|
|
|
|
|
<Skeleton height={40} mt={10} />
|
|
|
|
|
<Skeleton height={40} mt={10} />
|
|
|
|
|
</>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isError) {
|
|
|
|
|
return (
|
|
|
|
|
<Group position="center">
|
|
|
|
|
<Alert
|
|
|
|
|
icon={<IconAlertCircle size={16} />}
|
|
|
|
|
my="lg"
|
|
|
|
|
title={t('queue.error.title')}
|
|
|
|
|
color="red"
|
|
|
|
|
radius="md"
|
|
|
|
|
>
|
|
|
|
|
{t('queue.error.message')}
|
|
|
|
|
<Code mt="sm" block>
|
|
|
|
|
{(error as AxiosError)?.response?.data as string}
|
|
|
|
|
</Code>
|
|
|
|
|
</Alert>
|
|
|
|
|
</Group>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!data || data.items.length <= 0) {
|
|
|
|
|
return (
|
|
|
|
|
<Center style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
|
|
|
|
|
<Title order={3}>{t('queue.empty')}</Title>
|
|
|
|
|
</Center>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-06 13:39:45 +09:00
|
|
|
// TODO: Set ScollArea dynamic height based on the widget size
|
2022-12-11 16:06:41 +01:00
|
|
|
return (
|
2023-01-06 13:39:45 +09:00
|
|
|
<Stack justify="space-around" spacing="xs">
|
|
|
|
|
<Table highlightOnHover style={{ tableLayout: 'fixed' }} ref={ref}>
|
|
|
|
|
<thead>
|
|
|
|
|
<tr>
|
|
|
|
|
<th style={{ width: 32 }} />
|
|
|
|
|
<th style={{ width: '75%' }}>{t('queue.header.name')}</th>
|
|
|
|
|
{sizeBreakpoint < width ? (
|
|
|
|
|
<th style={{ width: 100 }}>{t('queue.header.size')}</th>
|
|
|
|
|
) : null}
|
|
|
|
|
<th style={{ width: 60 }}>{t('queue.header.eta')}</th>
|
|
|
|
|
{progressBreakpoint < width ? (
|
|
|
|
|
<th style={{ width: progressbarBreakpoint > width ? 100 : 200 }}>
|
|
|
|
|
{t('queue.header.progress')}
|
|
|
|
|
</th>
|
|
|
|
|
) : null}
|
|
|
|
|
</tr>
|
|
|
|
|
</thead>
|
|
|
|
|
<tbody>
|
|
|
|
|
{data.items.map((nzb) => (
|
|
|
|
|
<tr key={nzb.id}>
|
|
|
|
|
<td>
|
|
|
|
|
{nzb.state === 'paused' ? (
|
|
|
|
|
<Tooltip label="NOT IMPLEMENTED">
|
|
|
|
|
<ActionIcon color="gray" variant="subtle" radius="xl" size="sm">
|
|
|
|
|
<IconPlayerPlay size="16" />
|
|
|
|
|
</ActionIcon>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
) : (
|
|
|
|
|
<Tooltip label="NOT IMPLEMENTED">
|
|
|
|
|
<ActionIcon color="primary" variant="subtle" radius="xl" size="sm">
|
|
|
|
|
<IconPlayerPause size="16" />
|
|
|
|
|
</ActionIcon>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
)}
|
|
|
|
|
</td>
|
|
|
|
|
<td>
|
|
|
|
|
<Tooltip position="top" label={nzb.name}>
|
|
|
|
|
<Text
|
|
|
|
|
style={{
|
|
|
|
|
whiteSpace: 'nowrap',
|
|
|
|
|
overflow: 'hidden',
|
|
|
|
|
textOverflow: 'ellipsis',
|
|
|
|
|
}}
|
|
|
|
|
size="xs"
|
|
|
|
|
color={nzb.state === 'paused' ? 'dimmed' : undefined}
|
|
|
|
|
>
|
|
|
|
|
{nzb.name}
|
|
|
|
|
</Text>
|
|
|
|
|
</Tooltip>
|
|
|
|
|
</td>
|
2022-12-11 16:06:41 +01:00
|
|
|
{sizeBreakpoint < width ? (
|
2023-01-06 13:39:45 +09:00
|
|
|
<td>
|
|
|
|
|
<Text size="xs">{humanFileSize(nzb.size)}</Text>
|
|
|
|
|
</td>
|
2022-12-11 16:06:41 +01:00
|
|
|
) : null}
|
2023-01-06 13:39:45 +09:00
|
|
|
<td>
|
|
|
|
|
{nzb.eta <= 0 ? (
|
|
|
|
|
<Text size="xs" color="dimmed">
|
|
|
|
|
{t('queue.paused')}
|
|
|
|
|
</Text>
|
|
|
|
|
) : (
|
|
|
|
|
<Text size="xs">{dayjs.duration(nzb.eta, 's').format('H:mm:ss')}</Text>
|
|
|
|
|
)}
|
|
|
|
|
</td>
|
2022-12-11 16:06:41 +01:00
|
|
|
{progressBreakpoint < width ? (
|
2023-01-06 13:39:45 +09:00
|
|
|
<td style={{ display: 'flex', alignItems: 'center' }}>
|
|
|
|
|
<Text mr="sm" style={{ whiteSpace: 'nowrap' }}>
|
|
|
|
|
{nzb.progress.toFixed(1)}%
|
|
|
|
|
</Text>
|
|
|
|
|
{width > progressbarBreakpoint ? (
|
|
|
|
|
<Progress
|
|
|
|
|
radius="lg"
|
|
|
|
|
color={nzb.eta > 0 ? theme.primaryColor : 'lightgrey'}
|
|
|
|
|
value={nzb.progress}
|
|
|
|
|
size="lg"
|
|
|
|
|
style={{ width: '100%' }}
|
|
|
|
|
/>
|
|
|
|
|
) : null}
|
|
|
|
|
</td>
|
2022-12-11 16:06:41 +01:00
|
|
|
) : null}
|
|
|
|
|
</tr>
|
2023-01-06 13:39:45 +09:00
|
|
|
))}
|
|
|
|
|
</tbody>
|
|
|
|
|
</Table>
|
2022-12-11 16:06:41 +01:00
|
|
|
{totalPages > 1 && (
|
|
|
|
|
<Pagination
|
2023-01-06 13:39:45 +09:00
|
|
|
noWrap
|
2022-12-11 16:06:41 +01:00
|
|
|
size="sm"
|
|
|
|
|
position="center"
|
|
|
|
|
total={totalPages}
|
2023-03-03 00:37:22 +09:00
|
|
|
value={page}
|
2022-12-11 16:06:41 +01:00
|
|
|
onChange={setPage}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2023-01-06 13:39:45 +09:00
|
|
|
</Stack>
|
2022-12-11 16:06:41 +01:00
|
|
|
);
|
|
|
|
|
};
|