toaster refactoring
This commit is contained in:
@@ -52,7 +52,7 @@ const Transition = forwardRef(function Transition(
|
|||||||
type Props = {
|
type Props = {
|
||||||
open: boolean
|
open: boolean
|
||||||
onClose: () => void
|
onClose: () => void
|
||||||
onDownloadStart: () => void
|
onDownloadStart: (url: string) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function DownloadDialog({
|
export default function DownloadDialog({
|
||||||
@@ -120,7 +120,7 @@ export default function DownloadDialog({
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
resetInput()
|
resetInput()
|
||||||
setDownloadFormats(undefined)
|
setDownloadFormats(undefined)
|
||||||
onDownloadStart()
|
onDownloadStart(url)
|
||||||
}, 250)
|
}, 250)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,11 +3,14 @@ import { useRecoilState } from 'recoil'
|
|||||||
import { loadingAtom } from '../atoms/ui'
|
import { loadingAtom } from '../atoms/ui'
|
||||||
import DownloadDialog from './DownloadDialog'
|
import DownloadDialog from './DownloadDialog'
|
||||||
import HomeSpeedDial from './HomeSpeedDial'
|
import HomeSpeedDial from './HomeSpeedDial'
|
||||||
|
import { useToast } from '../hooks/toast'
|
||||||
|
|
||||||
const HomeActions: React.FC = () => {
|
const HomeActions: React.FC = () => {
|
||||||
const [, setIsLoading] = useRecoilState(loadingAtom)
|
const [, setIsLoading] = useRecoilState(loadingAtom)
|
||||||
const [openDialog, setOpenDialog] = useState(false)
|
const [openDialog, setOpenDialog] = useState(false)
|
||||||
|
|
||||||
|
const { pushMessage } = useToast()
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<HomeSpeedDial
|
<HomeSpeedDial
|
||||||
@@ -19,7 +22,8 @@ const HomeActions: React.FC = () => {
|
|||||||
setOpenDialog(false)
|
setOpenDialog(false)
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
}}
|
}}
|
||||||
onDownloadStart={() => {
|
onDownloadStart={(url) => {
|
||||||
|
pushMessage(`Requested ${url}`, 'info',)
|
||||||
setOpenDialog(false)
|
setOpenDialog(false)
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
}}
|
}}
|
||||||
|
|||||||
@@ -10,11 +10,11 @@ const Toaster: React.FC = () => {
|
|||||||
if (toasts.length > 0) {
|
if (toasts.length > 0) {
|
||||||
const closer = setInterval(() => {
|
const closer = setInterval(() => {
|
||||||
setToasts(t => t.map(t => ({ ...t, open: false })))
|
setToasts(t => t.map(t => ({ ...t, open: false })))
|
||||||
}, 1500)
|
}, 2000)
|
||||||
|
|
||||||
const cleaner = setInterval(() => {
|
const cleaner = setInterval(() => {
|
||||||
setToasts(t => t.filter((x) => (Date.now() - x.createdAt) < 1500))
|
setToasts(t => t.filter((x) => (Date.now() - x.createdAt) < 2000))
|
||||||
}, 1750)
|
}, 2250)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
clearInterval(closer)
|
clearInterval(closer)
|
||||||
|
|||||||
Reference in New Issue
Block a user