display yt-dlp version, multiple downloads enabled.
code refactoring preparations for optimistic ui updates for new downloads
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user