code refactoring
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
import { Suspense, useState } from 'react'
|
import { Suspense, useState } from 'react'
|
||||||
import { useRecoilState } from 'recoil'
|
import { useRecoilState } from 'recoil'
|
||||||
import { loadingAtom, optimisticDownloadsState } from '../atoms/ui'
|
import { loadingAtom } from '../atoms/ui'
|
||||||
import { useToast } from '../hooks/toast'
|
import { useToast } from '../hooks/toast'
|
||||||
import DownloadDialog from './DownloadDialog'
|
import DownloadDialog from './DownloadDialog'
|
||||||
import HomeSpeedDial from './HomeSpeedDial'
|
import HomeSpeedDial from './HomeSpeedDial'
|
||||||
@@ -8,32 +8,12 @@ import TemplatesEditor from './TemplatesEditor'
|
|||||||
|
|
||||||
const HomeActions: React.FC = () => {
|
const HomeActions: React.FC = () => {
|
||||||
const [, setIsLoading] = useRecoilState(loadingAtom)
|
const [, setIsLoading] = useRecoilState(loadingAtom)
|
||||||
const [optimistic, setOptimistic] = useRecoilState(optimisticDownloadsState)
|
|
||||||
|
|
||||||
const [openDownload, setOpenDownload] = useState(false)
|
const [openDownload, setOpenDownload] = useState(false)
|
||||||
const [openEditor, setOpenEditor] = useState(false)
|
const [openEditor, setOpenEditor] = useState(false)
|
||||||
|
|
||||||
const { pushMessage } = useToast()
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<HomeSpeedDial
|
<HomeSpeedDial
|
||||||
@@ -49,7 +29,6 @@ const HomeActions: React.FC = () => {
|
|||||||
}}
|
}}
|
||||||
// TODO: handle optimistic UI update
|
// TODO: handle optimistic UI update
|
||||||
onDownloadStart={(url) => {
|
onDownloadStart={(url) => {
|
||||||
handleOptimisticUpdate(url)
|
|
||||||
pushMessage(`Requested ${url}`, 'info')
|
pushMessage(`Requested ${url}`, 'info')
|
||||||
setOpenDownload(false)
|
setOpenDownload(false)
|
||||||
setIsLoading(true)
|
setIsLoading(true)
|
||||||
|
|||||||
@@ -154,6 +154,7 @@ func (s *Service) UpdateExecutable(args NoArgs, updated *bool) error {
|
|||||||
err := updater.UpdateExecutable()
|
err := updater.UpdateExecutable()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
*updated = true
|
*updated = true
|
||||||
|
s.logger.Info("Succesfully updated yt-dlp")
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
*updated = false
|
*updated = false
|
||||||
|
|||||||
Reference in New Issue
Block a user