import { Alert, Center, Code, Group, Pagination, Skeleton, Table, Text, Title, Tooltip, } from '@mantine/core'; import { IconAlertCircle } 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 { useGetUsenetHistory } from '../../tools/hooks/api'; import { humanFileSize } from '../../tools/humanFileSize'; dayjs.extend(duration); interface UsenetHistoryListProps { serviceId: string; } const PAGE_SIZE = 10; export const UsenetHistoryList: FunctionComponent = ({ serviceId }) => { const [page, setPage] = useState(1); const { t } = useTranslation('modules/usenet'); const { data, isLoading, isError, error } = useGetUsenetHistory({ 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('history.error')} {(error as AxiosError)?.response?.data as string} ); } if (!data || data.items.length <= 0) { return (
{t('history.empty')}
); } return ( <> {data.items.map((history) => ( ))}
{t('history.header.name')} {t('history.header.size')} {t('history.header.duration')}
{history.name} {humanFileSize(history.size)} {dayjs .duration(history.time, 's') .format(history.time < 60 ? 's [seconds]' : 'm [minutes] s [seconds] ')}
{totalPages > 1 && ( )} ); };