💄 Added modal on usenet widget (#1398)

This commit is contained in:
Tagaishi
2023-09-15 18:11:40 +02:00
committed by GitHub
parent d05c0023cd
commit 4c67ee2902
2 changed files with 138 additions and 80 deletions

View File

@@ -3,25 +3,26 @@ import {
Center, Center,
Code, Code,
Group, Group,
List,
Pagination, Pagination,
Popover,
Skeleton, Skeleton,
Stack, Stack,
Table, Table,
Text, Text,
Title, Title,
Tooltip,
} from '@mantine/core'; } from '@mantine/core';
import { useElementSize } from '@mantine/hooks'; import { useElementSize } from '@mantine/hooks';
import { IconAlertCircle } from '@tabler/icons-react'; import { IconAlertCircle, IconClock, IconFileDownload, IconFileInfo } from '@tabler/icons-react';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration'; import duration from 'dayjs/plugin/duration';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { FunctionComponent, useState } from 'react'; import { FunctionComponent, useState } from 'react';
import { useGetUsenetHistory } from '../dashDot/api';
import { parseDuration } from '~/tools/client/parseDuration'; import { parseDuration } from '~/tools/client/parseDuration';
import { humanFileSize } from '~/tools/humanFileSize'; import { humanFileSize } from '~/tools/humanFileSize';
import { useGetUsenetHistory } from '../dashDot/api';
dayjs.extend(duration); dayjs.extend(duration);
interface UsenetHistoryListProps { interface UsenetHistoryListProps {
@@ -87,16 +88,25 @@ export const UsenetHistoryList: FunctionComponent<UsenetHistoryListProps> = ({ a
<tr> <tr>
<th>{t('modules/usenet:history.header.name')}</th> <th>{t('modules/usenet:history.header.name')}</th>
<th style={{ width: 100 }}>{t('modules/usenet:history.header.size')}</th> <th style={{ width: 100 }}>{t('modules/usenet:history.header.size')}</th>
{durationBreakpoint < width ? ( {durationBreakpoint < width && (
<th style={{ width: 200 }}>{t('modules/usenet:history.header.duration')}</th> <th style={{ width: 200 }}>{t('modules/usenet:history.header.duration')}</th>
) : null} )}
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{data.items.map((history) => ( {data.items.map((history) => (
<Popover
withArrow
withinPortal
radius="lg"
shadow="sm"
transitionProps={{
transition: 'pop',
}}
>
<Popover.Target>
<tr key={history.id}> <tr key={history.id}>
<td> <td>
<Tooltip position="top" label={history.name}>
<Text <Text
size="xs" size="xs"
style={{ style={{
@@ -107,17 +117,29 @@ export const UsenetHistoryList: FunctionComponent<UsenetHistoryListProps> = ({ a
> >
{history.name} {history.name}
</Text> </Text>
</Tooltip>
</td> </td>
<td> <td>
<Text size="xs">{humanFileSize(history.size)}</Text> <Text size="xs">{humanFileSize(history.size)}</Text>
</td> </td>
{durationBreakpoint < width ? ( {durationBreakpoint < width && (
<td> <td>
<Text size="xs">{parseDuration(history.time, t)}</Text> <Text size="xs">{parseDuration(history.time, t)}</Text>
</td> </td>
) : null} )}
</tr> </tr>
</Popover.Target>
<Popover.Dropdown>
<List>
<List.Item icon={<IconFileInfo size={16} />}>{history.name}</List.Item>
<List.Item icon={<IconClock size={16} />}>
{parseDuration(history.time, t)}
</List.Item>
<List.Item icon={<IconFileDownload size={16} />}>
{humanFileSize(history.size)}
</List.Item>
</List>
</Popover.Dropdown>
</Popover>
))} ))}
</tbody> </tbody>
</Table> </Table>

View File

@@ -1,27 +1,35 @@
import { import {
ActionIcon,
Alert, Alert,
Center, Center,
Code, Code,
Group, Group,
List,
Pagination, Pagination,
Popover,
Progress, Progress,
Skeleton, Skeleton,
Stack, Stack,
Table, Table,
Text, Text,
Title, Title,
Tooltip,
useMantineTheme, useMantineTheme,
} from '@mantine/core'; } from '@mantine/core';
import { useElementSize } from '@mantine/hooks'; import { useElementSize } from '@mantine/hooks';
import { IconAlertCircle, IconPlayerPause, IconPlayerPlay } from '@tabler/icons-react'; import {
IconAlertCircle,
IconClock,
IconClockPause,
IconFileDownload,
IconFileInfo,
IconPercentage,
} from '@tabler/icons-react';
import dayjs from 'dayjs'; import dayjs from 'dayjs';
import duration from 'dayjs/plugin/duration'; import duration from 'dayjs/plugin/duration';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { FunctionComponent, useState } from 'react'; import { FunctionComponent, useState } from 'react';
import { parseDuration } from '~/tools/client/parseDuration';
import { humanFileSize } from '~/tools/humanFileSize'; import { humanFileSize } from '~/tools/humanFileSize';
import { useGetUsenetDownloads } from '../dashDot/api'; import { useGetUsenetDownloads } from '../dashDot/api';
dayjs.extend(duration); dayjs.extend(duration);
@@ -105,9 +113,18 @@ export const UsenetQueueList: FunctionComponent<UsenetQueueListProps> = ({ appId
</thead> </thead>
<tbody> <tbody>
{data.items.map((nzb) => ( {data.items.map((nzb) => (
<Popover
withArrow
withinPortal
radius="lg"
shadow="sm"
transitionProps={{
transition: 'pop',
}}
>
<Popover.Target>
<tr key={nzb.id}> <tr key={nzb.id}>
<td> <td>
<Tooltip position="top" label={nzb.name}>
<Text <Text
style={{ style={{
whiteSpace: 'nowrap', whiteSpace: 'nowrap',
@@ -119,7 +136,6 @@ export const UsenetQueueList: FunctionComponent<UsenetQueueListProps> = ({ appId
> >
{nzb.name} {nzb.name}
</Text> </Text>
</Tooltip>
</td> </td>
{sizeBreakpoint < width ? ( {sizeBreakpoint < width ? (
<td> <td>
@@ -152,6 +168,26 @@ export const UsenetQueueList: FunctionComponent<UsenetQueueListProps> = ({ appId
</td> </td>
) : null} ) : null}
</tr> </tr>
</Popover.Target>
<Popover.Dropdown>
<List>
<List.Item icon={<IconFileInfo size={16} />}>{nzb.name}</List.Item>
<List.Item icon={<IconPercentage size={16} />}>
{nzb.progress.toFixed(1)}%
</List.Item>
{nzb.state === 'downloading' ? (
<List.Item icon={<IconClock size={16} />}>
{parseDuration(nzb.eta, t)}
</List.Item>
) : (
<List.Item icon={<IconClockPause size={16} />}>{t('queue.paused')}</List.Item>
)}
<List.Item icon={<IconFileDownload size={16} />}>
{humanFileSize(nzb.size)}
</List.Item>
</List>
</Popover.Dropdown>
</Popover>
))} ))}
</tbody> </tbody>
</Table> </Table>