display yt-dlp version, multiple downloads enabled.

code refactoring
preparations for optimistic ui updates for new downloads
This commit is contained in:
2024-03-22 13:22:38 +01:00
parent 48c9258088
commit 43e5c94b58
10 changed files with 137 additions and 28 deletions

View File

@@ -1,6 +1,6 @@
import { Suspense, useState } from 'react'
import { useRecoilState } from 'recoil'
import { loadingAtom } from '../atoms/ui'
import { loadingAtom, optimisticDownloadsState } from '../atoms/ui'
import { useToast } from '../hooks/toast'
import DownloadDialog from './DownloadDialog'
import HomeSpeedDial from './HomeSpeedDial'
@@ -8,12 +8,32 @@ import TemplatesEditor from './TemplatesEditor'
const HomeActions: React.FC = () => {
const [, setIsLoading] = useRecoilState(loadingAtom)
const [optimistic, setOptimistic] = useRecoilState(optimisticDownloadsState)
const [openDownload, setOpenDownload] = useState(false)
const [openEditor, setOpenEditor] = useState(false)
const { pushMessage } = useToast()
// it's stupid because it will be overriden on the next server tick
const handleOptimisticUpdate = (url: string) => setOptimistic([
...optimistic, {
id: url,
info: {
created_at: new Date().toISOString(),
thumbnail: '',
title: url,
url: url
},
progress: {
eta: Number.MAX_SAFE_INTEGER,
percentage: '0%',
process_status: 0,
speed: 0
}
}
])
return (
<>
<HomeSpeedDial
@@ -27,7 +47,9 @@ const HomeActions: React.FC = () => {
setOpenDownload(false)
setIsLoading(true)
}}
// TODO: handle optimistic UI update
onDownloadStart={(url) => {
handleOptimisticUpdate(url)
pushMessage(`Requested ${url}`, 'info')
setOpenDownload(false)
setIsLoading(true)