diff --git a/data/configs/default.json b/data/configs/default.json index 066e4ac36..07dfe37b0 100644 --- a/data/configs/default.json +++ b/data/configs/default.json @@ -9,7 +9,9 @@ "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" } ], - "settings": {}, + "settings": { + "searchUrl": "https://google.com/search?q=" + }, "modules": { "Search Bar": { "enabled": true diff --git a/public/locales/en/modules/usenet.json b/public/locales/en/modules/usenet.json index 59f298103..30231fb80 100644 --- a/public/locales/en/modules/usenet.json +++ b/public/locales/en/modules/usenet.json @@ -3,6 +3,14 @@ "name": "Usenet", "description": "Show the queue and history of supported services" }, + "card": { + "errors": { + "noDownloadClients": { + "title": "No supported download clients found!", + "text": "Add a download service to view your current downloads" + } + } + }, "tabs": { "queue": "Queue", "history": "History" diff --git a/src/modules/usenet/UsenetModule.tsx b/src/modules/usenet/UsenetModule.tsx index 155734d59..f03084e69 100644 --- a/src/modules/usenet/UsenetModule.tsx +++ b/src/modules/usenet/UsenetModule.tsx @@ -1,6 +1,6 @@ -import { Badge, Button, Group, Select, Tabs } from '@mantine/core'; +import { Badge, Button, Group, Select, Stack, Tabs, Text, Title } from '@mantine/core'; import { IconDownload, IconPlayerPause, IconPlayerPlay } from '@tabler/icons'; -import { FunctionComponent, useState } from 'react'; +import { FunctionComponent, useEffect, useState } from 'react'; import { useTranslation } from 'next-i18next'; import dayjs from 'dayjs'; @@ -11,18 +11,39 @@ 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; } diff --git a/src/modules/usenet/UsenetQueueList.tsx b/src/modules/usenet/UsenetQueueList.tsx index 7198b9511..bc6d5ea0c 100644 --- a/src/modules/usenet/UsenetQueueList.tsx +++ b/src/modules/usenet/UsenetQueueList.tsx @@ -1,6 +1,6 @@ import { + ActionIcon, Alert, - Button, Center, Code, Group, @@ -90,13 +90,17 @@ export const UsenetQueueList: FunctionComponent = ({ servi {nzb.state === 'paused' ? ( - + + + + + ) : ( - + + + + + )} diff --git a/src/tools/hooks/api.ts b/src/tools/hooks/api.ts index 22cb6987b..ee4b5cf1d 100644 --- a/src/tools/hooks/api.ts +++ b/src/tools/hooks/api.ts @@ -14,6 +14,8 @@ import { UsenetPauseRequestParams } from '../../pages/api/modules/usenet/pause'; import { queryClient } from '../queryClient'; import { UsenetResumeRequestParams } from '../../pages/api/modules/usenet/resume'; +const POLLING_INTERVAL = 2000; + export const useGetUsenetInfo = (params: UsenetInfoRequestParams) => useQuery( ['usenetInfo', params.serviceId], @@ -24,9 +26,10 @@ export const useGetUsenetInfo = (params: UsenetInfoRequestParams) => }) ).data, { - refetchInterval: 1000, + refetchInterval: POLLING_INTERVAL, keepPreviousData: true, retry: 2, + enabled: !!params.serviceId, } ); @@ -40,7 +43,7 @@ export const useGetUsenetDownloads = (params: UsenetQueueRequestParams) => }) ).data, { - refetchInterval: 1000, + refetchInterval: POLLING_INTERVAL, keepPreviousData: true, retry: 2, } @@ -56,7 +59,7 @@ export const useGetUsenetHistory = (params: UsenetHistoryRequestParams) => }) ).data, { - refetchInterval: 1000, + refetchInterval: POLLING_INTERVAL, keepPreviousData: true, retry: 2, }