code refactoring

This commit is contained in:
2024-04-10 12:52:17 +02:00
parent 2f02293a52
commit d336b92e46
2 changed files with 2 additions and 22 deletions

View File

@@ -1,6 +1,6 @@
import { Suspense, useState } from 'react'
import { useRecoilState } from 'recoil'
import { loadingAtom, optimisticDownloadsState } from '../atoms/ui'
import { loadingAtom } from '../atoms/ui'
import { useToast } from '../hooks/toast'
import DownloadDialog from './DownloadDialog'
import HomeSpeedDial from './HomeSpeedDial'
@@ -8,32 +8,12 @@ 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
@@ -49,7 +29,6 @@ const HomeActions: React.FC = () => {
}}
// TODO: handle optimistic UI update
onDownloadStart={(url) => {
handleOptimisticUpdate(url)
pushMessage(`Requested ${url}`, 'info')
setOpenDownload(false)
setIsLoading(true)

View File

@@ -154,6 +154,7 @@ func (s *Service) UpdateExecutable(args NoArgs, updated *bool) error {
err := updater.UpdateExecutable()
if err != nil {
*updated = true
s.logger.Info("Succesfully updated yt-dlp")
return err
}
*updated = false