This commit is contained in:
2023-06-23 17:46:47 +02:00
parent 3067cee08c
commit 2c9d4b0a9b
2 changed files with 35 additions and 13 deletions

View File

@@ -1,6 +1,7 @@
import { FileUpload } from '@mui/icons-material' import { FileUpload } from '@mui/icons-material'
import CloseIcon from '@mui/icons-material/Close' import CloseIcon from '@mui/icons-material/Close'
import { import {
Backdrop,
Button, Button,
Container, Container,
FormControl, FormControl,
@@ -21,7 +22,7 @@ import Toolbar from '@mui/material/Toolbar'
import { TransitionProps } from '@mui/material/transitions' import { TransitionProps } from '@mui/material/transitions'
import Typography from '@mui/material/Typography' import Typography from '@mui/material/Typography'
import { Buffer } from 'buffer' import { Buffer } from 'buffer'
import { forwardRef, useContext, useEffect, useMemo, useRef, useState } from 'react' import { forwardRef, useContext, useEffect, useMemo, useRef, useState, useTransition } from 'react'
import { useDispatch, useSelector } from 'react-redux' import { useDispatch, useSelector } from 'react-redux'
import FormatsGrid from '../components/FormatsGrid' import FormatsGrid from '../components/FormatsGrid'
import { CliArguments } from '../lib/argsParser' import { CliArguments } from '../lib/argsParser'
@@ -30,6 +31,7 @@ import { RPCClientContext } from '../providers/rpcClientProvider'
import { RootState } from '../stores/store' import { RootState } from '../stores/store'
import type { DLMetadata } from '../types' import type { DLMetadata } from '../types'
import { isValidURL, toFormatArgs } from '../utils' import { isValidURL, toFormatArgs } from '../utils'
import { isPending } from '@reduxjs/toolkit'
const Transition = forwardRef(function Transition( const Transition = forwardRef(function Transition(
props: TransitionProps & { props: TransitionProps & {
@@ -43,9 +45,14 @@ const Transition = forwardRef(function Transition(
type Props = { type Props = {
open: boolean open: boolean
onClose: () => void onClose: () => void
onDownloadStart: () => void
} }
export default function DownloadDialog({ open, onClose }: Props) { export default function DownloadDialog({
open,
onClose,
onDownloadStart
}: Props) {
// redux state // redux state
const settings = useSelector((state: RootState) => state.settings) const settings = useSelector((state: RootState) => state.settings)
const status = useSelector((state: RootState) => state.status) const status = useSelector((state: RootState) => state.status)
@@ -90,6 +97,9 @@ export default function DownloadDialog({ open, onClose }: Props) {
setFilenameOverride(localStorage.getItem('last-filename-override') ?? '') setFilenameOverride(localStorage.getItem('last-filename-override') ?? '')
}, []) }, [])
// transitions
const [isPending, startTransition] = useTransition()
/** /**
* Retrive url from input, cli-arguments from checkboxes and emits via WebSocket * Retrive url from input, cli-arguments from checkboxes and emits via WebSocket
*/ */
@@ -112,7 +122,7 @@ export default function DownloadDialog({ open, onClose }: Props) {
setTimeout(() => { setTimeout(() => {
resetInput() resetInput()
setDownloadFormats(undefined) setDownloadFormats(undefined)
onClose() onDownloadStart()
}, 250) }, 250)
} }
@@ -195,6 +205,10 @@ export default function DownloadDialog({ open, onClose }: Props) {
onClose={onClose} onClose={onClose}
TransitionComponent={Transition} TransitionComponent={Transition}
> >
<Backdrop
sx={{ color: '#fff', zIndex: (theme) => theme.zIndex.drawer + 1 }}
open={isPending}
/>
<AppBar sx={{ position: 'relative' }}> <AppBar sx={{ position: 'relative' }}>
<Toolbar> <Toolbar>
<IconButton <IconButton
@@ -295,7 +309,10 @@ export default function DownloadDialog({ open, onClose }: Props) {
<Button <Button
variant="contained" variant="contained"
disabled={url === ''} disabled={url === ''}
onClick={() => settings.formatSelection ? sendUrlFormatSelection() : sendUrl()} onClick={() => settings.formatSelection
? startTransition(() => sendUrlFormatSelection())
: sendUrl()
}
> >
{settings.formatSelection ? i18n.t('selectFormatButton') : i18n.t('startButton')} {settings.formatSelection ? i18n.t('selectFormatButton') : i18n.t('startButton')}
</Button> </Button>

View File

@@ -99,7 +99,7 @@ export default function Home() {
if (activeDownloads && activeDownloads.length >= 0) { if (activeDownloads && activeDownloads.length >= 0) {
setShowBackdrop(false) setShowBackdrop(false)
} }
}, [activeDownloads]) }, [activeDownloads?.length])
/** /**
* Abort a specific download if id's provided, other wise abort all running ones. * Abort a specific download if id's provided, other wise abort all running ones.
@@ -165,12 +165,17 @@ export default function Home() {
onClick={() => setOpenDialog(true)} onClick={() => setOpenDialog(true)}
/> />
</SpeedDial> </SpeedDial>
<DownloadDialog open={openDialog} onClose={() => { <DownloadDialog
open={openDialog}
onClose={() => {
setOpenDialog(false) setOpenDialog(false)
activeDownloads?.length === 0 setShowBackdrop(false)
? setShowBackdrop(false) }}
: setShowBackdrop(true) onDownloadStart={() => {
}} /> setOpenDialog(false)
setShowBackdrop(true)
}}
/>
</Container> </Container>
) )
} }