import { Badge, Button, Group, Select, Stack, Tabs, Text, Title } from '@mantine/core'; import { useElementSize } from '@mantine/hooks'; import { IconFileDownload, IconPlayerPause, IconPlayerPlay } from '@tabler/icons-react'; import dayjs from 'dayjs'; import duration from 'dayjs/plugin/duration'; import { useTranslation } from 'next-i18next'; import { useEffect, useState } from 'react'; import { useConfigContext } from '../../config/provider'; import { MIN_WIDTH_MOBILE } from '../../constants/constants'; import { useGetUsenetInfo, usePauseUsenetQueueMutation, useResumeUsenetQueueMutation, } from '../dashDot/api'; import { humanFileSize } from '../../tools/humanFileSize'; import { AppIntegrationType } from '../../types/app'; import { defineWidget } from '../helper'; import { IWidget } from '../widgets'; import { UsenetHistoryList } from './UsenetHistoryList'; import { UsenetQueueList } from './UsenetQueueList'; dayjs.extend(duration); const downloadAppTypes: AppIntegrationType['type'][] = ['sabnzbd', 'nzbGet']; const definition = defineWidget({ id: 'usenet', icon: IconFileDownload, options: {}, component: UseNetTile, gridstack: { minWidth: 2, minHeight: 3, maxWidth: 12, maxHeight: 12, }, }); export type IUsenetWidget = IWidget<(typeof definition)['id'], typeof definition>; interface UseNetTileProps { widget: IUsenetWidget; } function UseNetTile({ widget }: UseNetTileProps) { const { t } = useTranslation('modules/usenet'); const { config } = useConfigContext(); const downloadApps = config?.apps.filter((x) => x.integration && downloadAppTypes.includes(x.integration.type)) ?? []; const { ref, width, height } = useElementSize(); const [selectedAppId, setSelectedApp] = useState(downloadApps[0]?.id); const { data } = useGetUsenetInfo({ appId: selectedAppId! }); useEffect(() => { if (!selectedAppId && downloadApps.length) { setSelectedApp(downloadApps[0].id); } }, [downloadApps, selectedAppId]); const pauseAsync = usePauseUsenetQueueMutation({ appId: selectedAppId! }); const resumeAsync = useResumeUsenetQueueMutation({ appId: selectedAppId! }); if (downloadApps.length === 0) { return ( {t('card.errors.noDownloadClients.title')} {t('card.errors.noDownloadClients.text')} ); } if (!selectedAppId) { return null; } return ( {t('tabs.queue')} {t('tabs.history')} {data && ( {width > MIN_WIDTH_MOBILE && ( <> {humanFileSize(data?.speed)}/s {t('info.sizeLeft')}: {humanFileSize(data?.sizeLeft)} )} )} {downloadApps.length > 1 && (