Fix minor issues

This commit is contained in:
Jannes Vandepitte
2022-08-26 16:43:46 +02:00
parent bf93fc87ee
commit 281f7bacb0
5 changed files with 51 additions and 13 deletions

View File

@@ -9,7 +9,9 @@
"url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ" "url": "https://www.youtube.com/watch?v=dQw4w9WgXcQ"
} }
], ],
"settings": {}, "settings": {
"searchUrl": "https://google.com/search?q="
},
"modules": { "modules": {
"Search Bar": { "Search Bar": {
"enabled": true "enabled": true

View File

@@ -3,6 +3,14 @@
"name": "Usenet", "name": "Usenet",
"description": "Show the queue and history of supported services" "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": { "tabs": {
"queue": "Queue", "queue": "Queue",
"history": "History" "history": "History"

View File

@@ -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 { IconDownload, IconPlayerPause, IconPlayerPlay } from '@tabler/icons';
import { FunctionComponent, useState } from 'react'; import { FunctionComponent, useEffect, useState } from 'react';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
@@ -11,18 +11,39 @@ import { UsenetHistoryList } from './UsenetHistoryList';
import { useGetServiceByType } from '../../tools/hooks/useGetServiceByType'; import { useGetServiceByType } from '../../tools/hooks/useGetServiceByType';
import { useGetUsenetInfo, usePauseUsenetQueue, useResumeUsenetQueue } from '../../tools/hooks/api'; import { useGetUsenetInfo, usePauseUsenetQueue, useResumeUsenetQueue } from '../../tools/hooks/api';
import { humanFileSize } from '../../tools/humanFileSize'; import { humanFileSize } from '../../tools/humanFileSize';
import { AddItemShelfButton } from '../../components/AppShelf/AddAppShelfItem';
dayjs.extend(duration); dayjs.extend(duration);
export const UsenetComponent: FunctionComponent = () => { export const UsenetComponent: FunctionComponent = () => {
const downloadServices = useGetServiceByType('Sabnzbd'); const downloadServices = useGetServiceByType('Sabnzbd');
const { t } = useTranslation('modules/usenet'); const { t } = useTranslation('modules/usenet');
const [selectedServiceId, setSelectedService] = useState<string | null>(downloadServices[0]?.id); const [selectedServiceId, setSelectedService] = useState<string | null>(downloadServices[0]?.id);
const { data } = useGetUsenetInfo({ serviceId: selectedServiceId! }); const { data } = useGetUsenetInfo({ serviceId: selectedServiceId! });
useEffect(() => {
if (!selectedServiceId && downloadServices.length) {
setSelectedService(downloadServices[0].id);
}
}, [downloadServices, selectedServiceId]);
const { mutate: pause } = usePauseUsenetQueue({ serviceId: selectedServiceId! }); const { mutate: pause } = usePauseUsenetQueue({ serviceId: selectedServiceId! });
const { mutate: resume } = useResumeUsenetQueue({ serviceId: selectedServiceId! }); const { mutate: resume } = useResumeUsenetQueue({ serviceId: selectedServiceId! });
if (downloadServices.length === 0) {
return (
<Stack>
<Title order={3}>{t('card.errors.noDownloadClients.title')}</Title>
<Group>
<Text>{t('card.errors.noDownloadClients.text')}</Text>
<AddItemShelfButton />
</Group>
</Stack>
);
}
if (!selectedServiceId) { if (!selectedServiceId) {
return null; return null;
} }

View File

@@ -1,6 +1,6 @@
import { import {
ActionIcon,
Alert, Alert,
Button,
Center, Center,
Code, Code,
Group, Group,
@@ -90,13 +90,17 @@ export const UsenetQueueList: FunctionComponent<UsenetQueueListProps> = ({ servi
<tr key={nzb.id}> <tr key={nzb.id}>
<td> <td>
{nzb.state === 'paused' ? ( {nzb.state === 'paused' ? (
<Button disabled color="gray" variant="subtle" radius="lg" size="xs" compact> <Tooltip label="NOT IMPLEMENTED">
<IconPlayerPlay size="16" /> <ActionIcon color="gray" variant="subtle" radius="xl" size="sm">
</Button> <IconPlayerPlay size="16" />
</ActionIcon>
</Tooltip>
) : ( ) : (
<Button disabled variant="subtle" radius="lg" size="xs" compact> <Tooltip label="NOT IMPLEMENTED">
<IconPlayerPause size="16" /> <ActionIcon color="primary" variant="subtle" radius="xl" size="sm">
</Button> <IconPlayerPause size="16" />
</ActionIcon>
</Tooltip>
)} )}
</td> </td>
<td> <td>

View File

@@ -14,6 +14,8 @@ import { UsenetPauseRequestParams } from '../../pages/api/modules/usenet/pause';
import { queryClient } from '../queryClient'; import { queryClient } from '../queryClient';
import { UsenetResumeRequestParams } from '../../pages/api/modules/usenet/resume'; import { UsenetResumeRequestParams } from '../../pages/api/modules/usenet/resume';
const POLLING_INTERVAL = 2000;
export const useGetUsenetInfo = (params: UsenetInfoRequestParams) => export const useGetUsenetInfo = (params: UsenetInfoRequestParams) =>
useQuery( useQuery(
['usenetInfo', params.serviceId], ['usenetInfo', params.serviceId],
@@ -24,9 +26,10 @@ export const useGetUsenetInfo = (params: UsenetInfoRequestParams) =>
}) })
).data, ).data,
{ {
refetchInterval: 1000, refetchInterval: POLLING_INTERVAL,
keepPreviousData: true, keepPreviousData: true,
retry: 2, retry: 2,
enabled: !!params.serviceId,
} }
); );
@@ -40,7 +43,7 @@ export const useGetUsenetDownloads = (params: UsenetQueueRequestParams) =>
}) })
).data, ).data,
{ {
refetchInterval: 1000, refetchInterval: POLLING_INTERVAL,
keepPreviousData: true, keepPreviousData: true,
retry: 2, retry: 2,
} }
@@ -56,7 +59,7 @@ export const useGetUsenetHistory = (params: UsenetHistoryRequestParams) =>
}) })
).data, ).data,
{ {
refetchInterval: 1000, refetchInterval: POLLING_INTERVAL,
keepPreviousData: true, keepPreviousData: true,
retry: 2, retry: 2,
} }