import { Badge, Button, Group, Select, Stack, Tabs, Text, Title, useMantineTheme, } from '@mantine/core'; import { IconDownload, IconPlayerPause, IconPlayerPlay } from '@tabler/icons'; import { FunctionComponent, useEffect, useState } from 'react'; import { useTranslation } from 'next-i18next'; import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration'; import { useElementSize } from '@mantine/hooks'; import { IModule } from '../ModuleTypes'; import { useGetServiceByType } from '../../tools/hooks/useGetServiceByType'; import { useGetUsenetInfo, usePauseUsenetQueue, useResumeUsenetQueue } from '../../tools/hooks/api'; import { humanFileSize } from '../../tools/humanFileSize'; import { UsenetQueueList } from '../../widgets/useNet/UsenetQueueList'; import { UsenetHistoryList } from '../../widgets/useNet/UsenetHistoryList'; dayjs.extend(duration); export const UsenetComponent: FunctionComponent = () => { const downloadServices = useGetServiceByType('Sabnzbd', 'NZBGet'); const { t } = useTranslation('modules/usenet'); const [selectedServiceId, setSelectedService] = useState(downloadServices[0]?.id); const { data } = useGetUsenetInfo({ appId: selectedServiceId! }); useEffect(() => { if (!selectedServiceId && downloadServices.length) { setSelectedService(downloadServices[0].id); } }, [downloadServices, selectedServiceId]); const { mutate: pause } = usePauseUsenetQueue({ appId: selectedServiceId! }); const { mutate: resume } = useResumeUsenetQueue({ appId: selectedServiceId! }); if (downloadServices.length === 0) { return ( {t('card.errors.noDownloadClients.title')} {t('card.errors.noDownloadClients.text')} ); } if (!selectedServiceId) { return null; } const { ref, width, height } = useElementSize(); const MIN_WIDTH_MOBILE = useMantineTheme().breakpoints.xs; return ( {t('tabs.queue')} {t('tabs.history')} {data && ( {width > MIN_WIDTH_MOBILE && ( <> {humanFileSize(data?.speed)}/s {t('info.sizeLeft')}: {humanFileSize(data?.sizeLeft)} )} {data.paused ? ( ) : ( )} )} {downloadServices.length > 1 && (