Address PR comments

This commit is contained in:
Jannes Vandepitte
2022-08-26 21:38:28 +02:00
parent 4db9dba2f4
commit 12e7eb6357
5 changed files with 58 additions and 18 deletions

View File

@@ -2,5 +2,10 @@
"actions": { "actions": {
"save": "Save" "save": "Save"
}, },
"tip": "Tip: " "tip": "Tip: ",
} "time": {
"seconds": "seconds",
"minutes": "minutes",
"hours": "hours"
}
}

View File

@@ -27,7 +27,10 @@
"progress": "Progress" "progress": "Progress"
}, },
"empty": "Queue is empty.", "empty": "Queue is empty.",
"error": "Some error has occured while fetching data:", "error": {
"title": "Error!",
"message": "Some error has occured while fetching data:"
},
"paused": "Paused" "paused": "Paused"
}, },
"history": { "history": {
@@ -37,7 +40,10 @@
"duration": "Download Duration" "duration": "Download Duration"
}, },
"empty": "Queue is empty.", "empty": "Queue is empty.",
"error": "Some error has occured while fetching data:", "error": {
"title": "Error!",
"message": "Some error has occured while fetching data:"
},
"paused": "Paused" "paused": "Paused"
} }
} }

View File

@@ -18,6 +18,7 @@ import { useTranslation } from 'next-i18next';
import { FunctionComponent, useState } from 'react'; import { FunctionComponent, useState } from 'react';
import { useGetUsenetHistory } from '../../tools/hooks/api'; import { useGetUsenetHistory } from '../../tools/hooks/api';
import { humanFileSize } from '../../tools/humanFileSize'; import { humanFileSize } from '../../tools/humanFileSize';
import { parseDuration } from '../../tools/parseDuration';
dayjs.extend(duration); dayjs.extend(duration);
@@ -29,7 +30,7 @@ const PAGE_SIZE = 10;
export const UsenetHistoryList: FunctionComponent<UsenetHistoryListProps> = ({ serviceId }) => { export const UsenetHistoryList: FunctionComponent<UsenetHistoryListProps> = ({ serviceId }) => {
const [page, setPage] = useState(1); const [page, setPage] = useState(1);
const { t } = useTranslation('modules/usenet'); const { t } = useTranslation(['modules/usenet', 'common']);
const { data, isLoading, isError, error } = useGetUsenetHistory({ const { data, isLoading, isError, error } = useGetUsenetHistory({
limit: PAGE_SIZE, limit: PAGE_SIZE,
@@ -51,8 +52,14 @@ export const UsenetHistoryList: FunctionComponent<UsenetHistoryListProps> = ({ s
if (isError) { if (isError) {
return ( return (
<Group position="center"> <Group position="center">
<Alert icon={<IconAlertCircle size={16} />} my="lg" title="Error!" color="red" radius="md"> <Alert
{t('history.error')} icon={<IconAlertCircle size={16} />}
my="lg"
title={t('modules/usenet:history.error.title')}
color="red"
radius="md"
>
{t('modules/usenet:history.error.message')}
<Code mt="sm" block> <Code mt="sm" block>
{(error as AxiosError)?.response?.data as string} {(error as AxiosError)?.response?.data as string}
</Code> </Code>
@@ -64,7 +71,7 @@ export const UsenetHistoryList: FunctionComponent<UsenetHistoryListProps> = ({ s
if (!data || data.items.length <= 0) { if (!data || data.items.length <= 0) {
return ( return (
<Center style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}> <Center style={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<Title order={3}>{t('history.empty')}</Title> <Title order={3}>{t('modules/usenet:history.empty')}</Title>
</Center> </Center>
); );
} }
@@ -79,9 +86,9 @@ export const UsenetHistoryList: FunctionComponent<UsenetHistoryListProps> = ({ s
</colgroup> </colgroup>
<thead> <thead>
<tr> <tr>
<th>{t('history.header.name')}</th> <th>{t('modules/usenet:history.header.name')}</th>
<th>{t('history.header.size')}</th> <th>{t('modules/usenet:history.header.size')}</th>
<th>{t('history.header.duration')}</th> <th>{t('modules/usenet:history.header.duration')}</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -105,11 +112,7 @@ export const UsenetHistoryList: FunctionComponent<UsenetHistoryListProps> = ({ s
<Text size="xs">{humanFileSize(history.size)}</Text> <Text size="xs">{humanFileSize(history.size)}</Text>
</td> </td>
<td> <td>
<Text size="xs"> <Text size="xs">{parseDuration(history.time, t)}</Text>
{dayjs
.duration(history.time, 's')
.format(history.time < 60 ? 's [seconds]' : 'm [minutes] s [seconds] ')}
</Text>
</td> </td>
</tr> </tr>
))} ))}

View File

@@ -55,8 +55,14 @@ export const UsenetQueueList: FunctionComponent<UsenetQueueListProps> = ({ servi
if (isError) { if (isError) {
return ( return (
<Group position="center"> <Group position="center">
<Alert icon={<IconAlertCircle size={16} />} my="lg" title="Error!" color="red" radius="md"> <Alert
{t('queue.error')} icon={<IconAlertCircle size={16} />}
my="lg"
title={t('queue.error.title')}
color="red"
radius="md"
>
{t('queue.error.message')}
<Code mt="sm" block> <Code mt="sm" block>
{(error as AxiosError)?.response?.data as string} {(error as AxiosError)?.response?.data as string}
</Code> </Code>

View File

@@ -0,0 +1,20 @@
import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration';
import { TFunction } from 'next-i18next';
dayjs.extend(duration);
export const parseDuration = (time: number, t: TFunction): string => {
const etaDuration = dayjs.duration(time, 's');
let eta = etaDuration.format(`s [${t('common:time.seconds')}]`);
if (etaDuration.asMinutes() > 1) {
eta = etaDuration.format(`m [${t('common:time.minutes')}] `) + eta;
}
if (etaDuration.asHours() > 1) {
eta = etaDuration.format(`H [${t('common:time.hours')}] `) + eta;
}
return eta;
};