From 2c9d4b0a9b8ef77d8f265e722c7c4410673e5bf7 Mon Sep 17 00:00:00 2001 From: marcobaobao Date: Fri, 23 Jun 2023 17:46:47 +0200 Subject: [PATCH] bugfix --- frontend/src/components/DownloadDialog.tsx | 29 +++++++++++++++++----- frontend/src/views/Home.tsx | 19 ++++++++------ 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/frontend/src/components/DownloadDialog.tsx b/frontend/src/components/DownloadDialog.tsx index 45f3640..63fd708 100644 --- a/frontend/src/components/DownloadDialog.tsx +++ b/frontend/src/components/DownloadDialog.tsx @@ -1,6 +1,7 @@ import { FileUpload } from '@mui/icons-material' import CloseIcon from '@mui/icons-material/Close' import { + Backdrop, Button, Container, FormControl, @@ -21,7 +22,7 @@ import Toolbar from '@mui/material/Toolbar' import { TransitionProps } from '@mui/material/transitions' import Typography from '@mui/material/Typography' 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 FormatsGrid from '../components/FormatsGrid' import { CliArguments } from '../lib/argsParser' @@ -30,6 +31,7 @@ import { RPCClientContext } from '../providers/rpcClientProvider' import { RootState } from '../stores/store' import type { DLMetadata } from '../types' import { isValidURL, toFormatArgs } from '../utils' +import { isPending } from '@reduxjs/toolkit' const Transition = forwardRef(function Transition( props: TransitionProps & { @@ -43,9 +45,14 @@ const Transition = forwardRef(function Transition( type Props = { open: boolean onClose: () => void + onDownloadStart: () => void } -export default function DownloadDialog({ open, onClose }: Props) { +export default function DownloadDialog({ + open, + onClose, + onDownloadStart +}: Props) { // redux state const settings = useSelector((state: RootState) => state.settings) const status = useSelector((state: RootState) => state.status) @@ -90,9 +97,12 @@ export default function DownloadDialog({ open, onClose }: Props) { 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 + */ const sendUrl = (immediate?: string) => { const codes = new Array() if (pickedVideoFormat !== '') codes.push(pickedVideoFormat) @@ -112,7 +122,7 @@ export default function DownloadDialog({ open, onClose }: Props) { setTimeout(() => { resetInput() setDownloadFormats(undefined) - onClose() + onDownloadStart() }, 250) } @@ -195,6 +205,10 @@ export default function DownloadDialog({ open, onClose }: Props) { onClose={onClose} TransitionComponent={Transition} > + theme.zIndex.drawer + 1 }} + open={isPending} + /> settings.formatSelection ? sendUrlFormatSelection() : sendUrl()} + onClick={() => settings.formatSelection + ? startTransition(() => sendUrlFormatSelection()) + : sendUrl() + } > {settings.formatSelection ? i18n.t('selectFormatButton') : i18n.t('startButton')} diff --git a/frontend/src/views/Home.tsx b/frontend/src/views/Home.tsx index 4ae9ddf..0333926 100644 --- a/frontend/src/views/Home.tsx +++ b/frontend/src/views/Home.tsx @@ -99,7 +99,7 @@ export default function Home() { if (activeDownloads && activeDownloads.length >= 0) { setShowBackdrop(false) } - }, [activeDownloads]) + }, [activeDownloads?.length]) /** * 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)} /> - { - setOpenDialog(false) - activeDownloads?.length === 0 - ? setShowBackdrop(false) - : setShowBackdrop(true) - }} /> + { + setOpenDialog(false) + setShowBackdrop(false) + }} + onDownloadStart={() => { + setOpenDialog(false) + setShowBackdrop(true) + }} + /> ) }