Download REST API endpoints (#72)
* backend and frontend hotfixes, see message Improved rendering on the frontend by cutting unecessary useStates. Backend side, downloads now auto resume even on application kill. * download rest api endpoints, general code refactor * download request json mappings
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
import { Grid, Snackbar } from "@mui/material"
|
||||
import { Fragment, useContext, useEffect, useState } from "react"
|
||||
import { Grid } from "@mui/material"
|
||||
import { Fragment, useContext } from "react"
|
||||
import { useToast } from "../hooks/toast"
|
||||
import { I18nContext } from "../providers/i18nProvider"
|
||||
import type { RPCResult } from "../types"
|
||||
import { StackableResult } from "./StackableResult"
|
||||
import { I18nContext } from "../providers/i18nProvider"
|
||||
|
||||
type Props = {
|
||||
downloads: RPCResult[]
|
||||
@@ -10,9 +11,8 @@ type Props = {
|
||||
}
|
||||
|
||||
export function DownloadsCardView({ downloads, onStop }: Props) {
|
||||
const [openSB, setOpenSB] = useState(false)
|
||||
|
||||
const { i18n } = useContext(I18nContext)
|
||||
const { pushMessage } = useToast()
|
||||
|
||||
return (
|
||||
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12 }} pt={2}>
|
||||
@@ -26,7 +26,7 @@ export function DownloadsCardView({ downloads, onStop }: Props) {
|
||||
thumbnail={download.info.thumbnail}
|
||||
percentage={download.progress.percentage}
|
||||
onStop={() => onStop(download.id)}
|
||||
onCopy={() => setOpenSB(true)}
|
||||
onCopy={() => pushMessage(i18n.t('clipboardAction'))}
|
||||
resolution={download.info.resolution ?? ''}
|
||||
speed={download.progress.speed}
|
||||
size={download.info.filesize_approx ?? 0}
|
||||
@@ -36,12 +36,6 @@ export function DownloadsCardView({ downloads, onStop }: Props) {
|
||||
</Grid>
|
||||
))
|
||||
}
|
||||
<Snackbar
|
||||
open={openSB}
|
||||
autoHideDuration={1250}
|
||||
onClose={() => setOpenSB(false)}
|
||||
message={i18n.t('clipboardAction')}
|
||||
/>
|
||||
</Grid>
|
||||
)
|
||||
}
|
||||
@@ -19,13 +19,13 @@ type Props = {
|
||||
onStop: (id: string) => void
|
||||
}
|
||||
|
||||
export function DownloadsListView({ downloads, onStop }: Props) {
|
||||
export const DownloadsListView: React.FC<Props> = ({ downloads, onStop }) => {
|
||||
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: '80vh' }} elevation={2}>
|
||||
<TableContainer component={Paper} sx={{ minHeight: '100%' }} elevation={2}>
|
||||
<Table>
|
||||
<TableHead>
|
||||
<TableHead hidden={downloads.length === 0}>
|
||||
<TableRow>
|
||||
<TableCell>
|
||||
<Typography fontWeight={500} fontSize={15}>Title</Typography>
|
||||
@@ -52,8 +52,9 @@ export function DownloadsListView({ downloads, onStop }: Props) {
|
||||
<TableCell>
|
||||
<LinearProgress
|
||||
value={
|
||||
download.progress.percentage === '-1' ? 100 :
|
||||
Number(download.progress.percentage.replace('%', ''))
|
||||
download.progress.percentage === '-1'
|
||||
? 100
|
||||
: Number(download.progress.percentage.replace('%', ''))
|
||||
}
|
||||
variant={
|
||||
download.progress.process_status === 0
|
||||
|
||||
Reference in New Issue
Block a user