💄 Fix white space on torrent (#1254)

* 💄 Fix white space on torrent

* 🐛 Fix issue with table content

* 🐛 Remove temporary mock value

---------

Co-authored-by: Meier Lukas <meierschlumpf@gmail.com>
This commit is contained in:
Manuel
2023-08-08 21:38:14 +02:00
committed by GitHub
parent e755bf6bd0
commit 9404b2c718
2 changed files with 31 additions and 14 deletions

View File

@@ -10,6 +10,7 @@ import {
Progress, Progress,
Stack, Stack,
Text, Text,
createStyles,
useMantineTheme, useMantineTheme,
} from '@mantine/core'; } from '@mantine/core';
import { useDisclosure, useElementSize } from '@mantine/hooks'; import { useDisclosure, useElementSize } from '@mantine/hooks';
@@ -24,6 +25,7 @@ import {
IconUpload, IconUpload,
} from '@tabler/icons-react'; } from '@tabler/icons-react';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { MIN_WIDTH_MOBILE } from '~/constants/constants';
import { calculateETA } from '../../tools/client/calculateEta'; import { calculateETA } from '../../tools/client/calculateEta';
import { humanFileSize } from '../../tools/humanFileSize'; import { humanFileSize } from '../../tools/humanFileSize';
@@ -32,12 +34,13 @@ import { AppType } from '../../types/app';
interface TorrentQueueItemProps { interface TorrentQueueItemProps {
torrent: NormalizedTorrent; torrent: NormalizedTorrent;
app?: AppType; app?: AppType;
width: number;
} }
export const BitTorrrentQueueItem = ({ torrent, app }: TorrentQueueItemProps) => { export const BitTorrrentQueueItem = ({ torrent, width, app }: TorrentQueueItemProps) => {
const [popoverOpened, { open: openPopover, close: closePopover }] = useDisclosure(false); const [popoverOpened, { open: openPopover, close: closePopover }] = useDisclosure(false);
const theme = useMantineTheme(); const theme = useMantineTheme();
const { width } = useElementSize(); const { classes } = useStyles();
const { t } = useTranslation('modules/torrents-status'); const { t } = useTranslation('modules/torrents-status');
const downloadSpeed = torrent.downloadSpeed / 1024 / 1024; const downloadSpeed = torrent.downloadSpeed / 1024 / 1024;
@@ -74,25 +77,33 @@ export const BitTorrrentQueueItem = ({ torrent, app }: TorrentQueueItemProps) =>
</Popover> </Popover>
</td> </td>
<td> <td>
<Text size="xs">{humanFileSize(size, false)}</Text> <Text className={classes.noTextBreak} size="xs">
{humanFileSize(size, false)}
</Text>
</td> </td>
{theme.fn.largerThan('xs') && ( {width > MIN_WIDTH_MOBILE && (
<td> <td>
<Text size="xs">{downloadSpeed > 0 ? `${downloadSpeed.toFixed(1)} Mb/s` : '-'}</Text> <Text className={classes.noTextBreak} size="xs">
{downloadSpeed > 0 ? `${downloadSpeed.toFixed(1)} Mb/s` : '-'}
</Text>
</td> </td>
)} )}
{theme.fn.largerThan('xs') && ( {width > MIN_WIDTH_MOBILE && (
<td> <td>
<Text size="xs">{uploadSpeed > 0 ? `${uploadSpeed.toFixed(1)} Mb/s` : '-'}</Text> <Text className={classes.noTextBreak} size="xs">
{uploadSpeed > 0 ? `${uploadSpeed.toFixed(1)} Mb/s` : '-'}
</Text>
</td> </td>
)} )}
{theme.fn.largerThan('xs') && ( {width > MIN_WIDTH_MOBILE && (
<td> <td>
<Text size="xs">{torrent.eta <= 0 ? '∞' : calculateETA(torrent.eta)}</Text> <Text className={classes.noTextBreak} size="xs">
{torrent.eta <= 0 ? '∞' : calculateETA(torrent.eta)}
</Text>
</td> </td>
)} )}
<td> <td>
<Text>{(torrent.progress * 100).toFixed(1)}%</Text> <Text className={classes.noTextBreak}>{(torrent.progress * 100).toFixed(1)}%</Text>
<Progress <Progress
radius="lg" radius="lg"
color={torrent.progress === 1 ? 'green' : torrent.state === 'paused' ? 'yellow' : 'blue'} color={torrent.progress === 1 ? 'green' : torrent.state === 'paused' ? 'yellow' : 'blue'}
@@ -104,7 +115,7 @@ export const BitTorrrentQueueItem = ({ torrent, app }: TorrentQueueItemProps) =>
); );
}; };
const TorrentQueuePopover = ({ torrent, app }: TorrentQueueItemProps) => { const TorrentQueuePopover = ({ torrent, app }: Omit<TorrentQueueItemProps, 'width'>) => {
const { t } = useTranslation('modules/torrents-status'); const { t } = useTranslation('modules/torrents-status');
const { colors } = useMantineTheme(); const { colors } = useMantineTheme();
@@ -219,3 +230,9 @@ const TorrentQueuePopover = ({ torrent, app }: TorrentQueueItemProps) => {
</Stack> </Stack>
); );
}; };
const useStyles = createStyles(() => ({
noTextBreak: {
whiteSpace: 'nowrap',
},
}));

View File

@@ -1,4 +1,4 @@
import { NormalizedTorrent } from '@ctrl/shared-torrent'; import { NormalizedTorrent, TorrentState } from '@ctrl/shared-torrent';
import { import {
Badge, Badge,
Center, Center,
@@ -19,9 +19,9 @@ import relativeTime from 'dayjs/plugin/relativeTime';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import { MIN_WIDTH_MOBILE } from '../../constants/constants'; import { MIN_WIDTH_MOBILE } from '../../constants/constants';
import { useGetDownloadClientsQueue } from '../download-speed/useGetNetworkSpeed';
import { NormalizedDownloadQueueResponse } from '../../types/api/downloads/queue/NormalizedDownloadQueueResponse'; import { NormalizedDownloadQueueResponse } from '../../types/api/downloads/queue/NormalizedDownloadQueueResponse';
import { AppIntegrationType } from '../../types/app'; import { AppIntegrationType } from '../../types/app';
import { useGetDownloadClientsQueue } from '../download-speed/useGetNetworkSpeed';
import { defineWidget } from '../helper'; import { defineWidget } from '../helper';
import { IWidget } from '../widgets'; import { IWidget } from '../widgets';
import { BitTorrrentQueueItem } from './TorrentQueueItem'; import { BitTorrrentQueueItem } from './TorrentQueueItem';
@@ -154,7 +154,7 @@ function TorrentTile({ widget }: TorrentTileProps) {
</thead> </thead>
<tbody> <tbody>
{filteredTorrents.map((torrent, index) => ( {filteredTorrents.map((torrent, index) => (
<BitTorrrentQueueItem key={index} torrent={torrent} app={undefined} /> <BitTorrrentQueueItem key={index} torrent={torrent} width={width} app={undefined} />
))} ))}
{filteredTorrents.length !== torrents.length && ( {filteredTorrents.length !== torrents.length && (