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 { 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 { 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"> Some error has occured while fetching data: {(error as AxiosError)?.response?.data as string} ); } if (!data || data.items.length <= 0) { return (
History is empty
); } return (
{data.items.map((history) => ( ))}
Name Size Download Duration
{history.name} {humanFileSize(history.size)} {dayjs .duration(history.time, 's') .format(history.time < 60 ? 's [seconds]' : 'm [minutes] s [seconds] ')}
); };