enable viewing results as listview
This commit is contained in:
33
frontend/src/components/DownloadsCardView.tsx
Normal file
33
frontend/src/components/DownloadsCardView.tsx
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Grid } from "@mui/material"
|
||||
import { Fragment } from "react"
|
||||
import type { RPCResult } from "../types"
|
||||
import { StackableResult } from "./StackableResult"
|
||||
|
||||
type Props = {
|
||||
downloads: RPCResult[]
|
||||
abortFunction: Function
|
||||
}
|
||||
|
||||
export function DownloadsCardView({ downloads, abortFunction }: Props) {
|
||||
return (
|
||||
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12 }} pt={2}>
|
||||
{
|
||||
downloads.map(download => (
|
||||
<Grid item xs={4} sm={8} md={6} key={download.id}>
|
||||
<Fragment>
|
||||
<StackableResult
|
||||
title={download.info.title}
|
||||
thumbnail={download.info.thumbnail}
|
||||
percentage={download.progress.percentage}
|
||||
stopCallback={() => abortFunction(download.id)}
|
||||
resolution={download.info.resolution ?? ''}
|
||||
speed={download.progress.speed}
|
||||
size={download.info.filesize_approx ?? 0}
|
||||
/>
|
||||
</Fragment>
|
||||
</Grid>
|
||||
))
|
||||
}
|
||||
</Grid>
|
||||
)
|
||||
}
|
||||
70
frontend/src/components/DownloadsListView.tsx
Normal file
70
frontend/src/components/DownloadsListView.tsx
Normal file
@@ -0,0 +1,70 @@
|
||||
import { Button, CircularProgress, Grid, LinearProgress, Paper, Table, TableBody, TableCell, TableContainer, TableHead, TableRow, Typography } from "@mui/material"
|
||||
import { RPCResult } from "../types"
|
||||
import { ellipsis, formatSpeedMiB, roundMiB } from "../utils"
|
||||
|
||||
type Props = {
|
||||
downloads: RPCResult[]
|
||||
abortFunction: Function
|
||||
}
|
||||
|
||||
export function DownloadsListView({ downloads, abortFunction }: Props) {
|
||||
return (
|
||||
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12 }} pt={2}>
|
||||
<Grid item xs={12}>
|
||||
<TableContainer component={Paper} sx={{ minHeight: '65vh' }} elevation={2}>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableRow>
|
||||
<TableCell>
|
||||
<Typography fontWeight={500} fontSize={15}>Title</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography fontWeight={500} fontSize={15}>Progress</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography fontWeight={500} fontSize={15}>Speed</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography fontWeight={500} fontSize={15}>Size</Typography>
|
||||
</TableCell>
|
||||
<TableCell>
|
||||
<Typography fontWeight={500} fontSize={15}>Actions</Typography>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableHead>
|
||||
<TableBody>
|
||||
{
|
||||
downloads.map(download => (
|
||||
<TableRow key={download.id}>
|
||||
<TableCell>{ellipsis(download.info.title, 80)}</TableCell>
|
||||
<TableCell>
|
||||
<LinearProgress
|
||||
value={
|
||||
download.progress.percentage === '-1' ? 100 :
|
||||
Number(download.progress.percentage.replace('%', ''))
|
||||
}
|
||||
variant="determinate"
|
||||
color={download.progress.percentage === '-1' ? 'success' : 'primary'}
|
||||
/>
|
||||
</TableCell>
|
||||
<TableCell>{formatSpeedMiB(download.progress.speed)}</TableCell>
|
||||
<TableCell>{roundMiB(download.info.filesize_approx ?? 0)}</TableCell>
|
||||
<TableCell>
|
||||
<Button
|
||||
variant="contained"
|
||||
size="small"
|
||||
onClick={() => abortFunction(download.id)}
|
||||
>
|
||||
{download.progress.percentage === '-1' ? 'Remove' : 'Stop'}
|
||||
</Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
))
|
||||
}
|
||||
</TableBody>
|
||||
</Table>
|
||||
</TableContainer>
|
||||
</Grid>
|
||||
</Grid>
|
||||
)
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import {
|
||||
Typography
|
||||
} from "@mui/material";
|
||||
import { useEffect, useState } from "react";
|
||||
import { ellipsis } from "../utils";
|
||||
import { ellipsis, formatSpeedMiB, roundMiB } from "../utils";
|
||||
|
||||
type Props = {
|
||||
title: string,
|
||||
@@ -42,6 +42,8 @@ export function StackableResult({
|
||||
}
|
||||
}, [percentage])
|
||||
|
||||
const percentageToNumber = () => isCompleted ? 100 : Number(percentage.replace('%', ''))
|
||||
|
||||
const guessResolution = (xByY: string): any => {
|
||||
if (!xByY) return null;
|
||||
if (xByY.includes('4320')) return (<EightK color="primary" />);
|
||||
@@ -51,11 +53,6 @@ export function StackableResult({
|
||||
return null;
|
||||
}
|
||||
|
||||
const percentageToNumber = () => isCompleted ? 100 : Number(percentage.replace('%', ''))
|
||||
|
||||
const roundMiB = (bytes: number) => `${(bytes / 1_000_000).toFixed(2)} MiB`
|
||||
const formatSpeedMiB = (val: number) => `${roundMiB(val)}/s`
|
||||
|
||||
return (
|
||||
<Card>
|
||||
<CardActionArea>
|
||||
|
||||
Reference in New Issue
Block a user