import { Badge, Button, Group, Select, Stack, Tabs, Text, Title } 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 { IModule } from '../ModuleTypes'; import { UsenetQueueList } from './UsenetQueueList'; import { UsenetHistoryList } from './UsenetHistoryList'; import { useGetServiceByType } from '../../tools/hooks/useGetServiceByType'; import { useGetUsenetInfo, usePauseUsenetQueue, useResumeUsenetQueue } from '../../tools/hooks/api'; import { humanFileSize } from '../../tools/humanFileSize'; import { AddItemShelfButton } from '../../components/AppShelf/AddAppShelfItem'; dayjs.extend(duration); export const UsenetComponent: FunctionComponent = () => { const downloadServices = useGetServiceByType('Sabnzbd'); const { t } = useTranslation('modules/usenet'); const [selectedServiceId, setSelectedService] = useState(downloadServices[0]?.id); const { data } = useGetUsenetInfo({ serviceId: selectedServiceId! }); useEffect(() => { if (!selectedServiceId && downloadServices.length) { setSelectedService(downloadServices[0].id); } }, [downloadServices, selectedServiceId]); const { mutate: pause } = usePauseUsenetQueue({ serviceId: selectedServiceId! }); const { mutate: resume } = useResumeUsenetQueue({ serviceId: selectedServiceId! }); if (downloadServices.length === 0) { return ( {t('card.errors.noDownloadClients.title')} {t('card.errors.noDownloadClients.text')} ); } if (!selectedServiceId) { return null; } return ( {t('tabs.queue')} {t('tabs.history')} {data && ( {humanFileSize(data?.speed)}/s {t('info.sizeLeft')}: {humanFileSize(data?.sizeLeft)} {data.paused ? ( ) : ( )} )} {downloadServices.length > 1 && (