From d100092f35fb4d8dc58c6dfd4706ab88d5905c0e Mon Sep 17 00:00:00 2001 From: marcobaobao Date: Fri, 20 Oct 2023 18:42:48 +0200 Subject: [PATCH] toaster refactoring --- frontend/src/components/DownloadDialog.tsx | 4 ++-- frontend/src/components/HomeActions.tsx | 6 +++++- frontend/src/providers/ToasterProvider.tsx | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/frontend/src/components/DownloadDialog.tsx b/frontend/src/components/DownloadDialog.tsx index c2a0e5e..7ccaf63 100644 --- a/frontend/src/components/DownloadDialog.tsx +++ b/frontend/src/components/DownloadDialog.tsx @@ -52,7 +52,7 @@ const Transition = forwardRef(function Transition( type Props = { open: boolean onClose: () => void - onDownloadStart: () => void + onDownloadStart: (url: string) => void } export default function DownloadDialog({ @@ -120,7 +120,7 @@ export default function DownloadDialog({ setTimeout(() => { resetInput() setDownloadFormats(undefined) - onDownloadStart() + onDownloadStart(url) }, 250) } diff --git a/frontend/src/components/HomeActions.tsx b/frontend/src/components/HomeActions.tsx index 1cae5de..b237e73 100644 --- a/frontend/src/components/HomeActions.tsx +++ b/frontend/src/components/HomeActions.tsx @@ -3,11 +3,14 @@ import { useRecoilState } from 'recoil' import { loadingAtom } from '../atoms/ui' import DownloadDialog from './DownloadDialog' import HomeSpeedDial from './HomeSpeedDial' +import { useToast } from '../hooks/toast' const HomeActions: React.FC = () => { const [, setIsLoading] = useRecoilState(loadingAtom) const [openDialog, setOpenDialog] = useState(false) + const { pushMessage } = useToast() + return ( <> { setOpenDialog(false) setIsLoading(true) }} - onDownloadStart={() => { + onDownloadStart={(url) => { + pushMessage(`Requested ${url}`, 'info',) setOpenDialog(false) setIsLoading(true) }} diff --git a/frontend/src/providers/ToasterProvider.tsx b/frontend/src/providers/ToasterProvider.tsx index 8f3ba91..fd04e4f 100644 --- a/frontend/src/providers/ToasterProvider.tsx +++ b/frontend/src/providers/ToasterProvider.tsx @@ -10,11 +10,11 @@ const Toaster: React.FC = () => { if (toasts.length > 0) { const closer = setInterval(() => { setToasts(t => t.map(t => ({ ...t, open: false }))) - }, 1500) + }, 2000) const cleaner = setInterval(() => { - setToasts(t => t.filter((x) => (Date.now() - x.createdAt) < 1500)) - }, 1750) + setToasts(t => t.filter((x) => (Date.now() - x.createdAt) < 2000)) + }, 2250) return () => { clearInterval(closer)