Skip to content

Commit

Permalink
toaster refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
marcopiovanello committed Oct 20, 2023
1 parent d64303c commit d100092
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/DownloadDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -120,7 +120,7 @@ export default function DownloadDialog({
setTimeout(() => {
resetInput()
setDownloadFormats(undefined)
onDownloadStart()
onDownloadStart(url)
}, 250)
}

Expand Down
6 changes: 5 additions & 1 deletion frontend/src/components/HomeActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<HomeSpeedDial
Expand All @@ -19,7 +22,8 @@ const HomeActions: React.FC = () => {
setOpenDialog(false)
setIsLoading(true)
}}
onDownloadStart={() => {
onDownloadStart={(url) => {
pushMessage(`Requested ${url}`, 'info',)
setOpenDialog(false)
setIsLoading(true)
}}
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/providers/ToasterProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d100092

Please sign in to comment.