frontend code refactoring

This commit is contained in:
2024-06-14 10:42:25 +02:00
parent ee18929196
commit 4066a6d5e3
8 changed files with 11 additions and 20 deletions

View File

@@ -1,6 +1,6 @@
{ {
"name": "yt-dlp-webui", "name": "yt-dlp-webui",
"version": "3.0.9", "version": "3.1.0",
"description": "Frontend compontent of yt-dlp-webui", "description": "Frontend compontent of yt-dlp-webui",
"scripts": { "scripts": {
"dev": "vite", "dev": "vite",

View File

@@ -3,7 +3,7 @@ import { useRecoilState, useRecoilValue } from 'recoil'
import { loadingDownloadsState } from '../atoms/downloads' import { loadingDownloadsState } from '../atoms/downloads'
import { listViewState } from '../atoms/settings' import { listViewState } from '../atoms/settings'
import { loadingAtom } from '../atoms/ui' import { loadingAtom } from '../atoms/ui'
import DownloadsCardView from './DownloadsCardView' import DownloadsGridView from './DownloadsGridView'
import DownloadsTableView from './DownloadsTableView' import DownloadsTableView from './DownloadsTableView'
const Downloads: React.FC = () => { const Downloads: React.FC = () => {
@@ -21,7 +21,7 @@ const Downloads: React.FC = () => {
if (tableView) return <DownloadsTableView /> if (tableView) return <DownloadsTableView />
return <DownloadsCardView /> return <DownloadsGridView />
} }
export default Downloads export default Downloads

View File

@@ -6,15 +6,13 @@ import { useI18n } from '../hooks/useI18n'
import { useRPC } from '../hooks/useRPC' import { useRPC } from '../hooks/useRPC'
import DownloadCard from './DownloadCard' import DownloadCard from './DownloadCard'
const DownloadsCardView: React.FC = () => { const DownloadsGridView: React.FC = () => {
const downloads = useRecoilValue(activeDownloadsState) const downloads = useRecoilValue(activeDownloadsState)
const { i18n } = useI18n() const { i18n } = useI18n()
const { client } = useRPC() const { client } = useRPC()
const { pushMessage } = useToast() const { pushMessage } = useToast()
const abort = (id: string) => client.kill(id)
return ( return (
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12, xl: 12 }} pt={2}> <Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12, xl: 12 }} pt={2}>
{ {
@@ -22,7 +20,7 @@ const DownloadsCardView: React.FC = () => {
<Grid item xs={4} sm={8} md={6} xl={4} key={download.id}> <Grid item xs={4} sm={8} md={6} xl={4} key={download.id}>
<DownloadCard <DownloadCard
download={download} download={download}
onStop={() => abort(download.id)} onStop={() => client.kill(download.id)}
onCopy={() => pushMessage(i18n.t('clipboardAction'), 'info')} onCopy={() => pushMessage(i18n.t('clipboardAction'), 'info')}
/> />
</Grid> </Grid>
@@ -32,4 +30,4 @@ const DownloadsCardView: React.FC = () => {
) )
} }
export default DownloadsCardView export default DownloadsGridView

View File

@@ -123,8 +123,6 @@ const DownloadsTableView: React.FC = () => {
const serverAddr = useRecoilValue(serverURL) const serverAddr = useRecoilValue(serverURL)
const { client } = useRPC() const { client } = useRPC()
const abort = (id: string) => client.kill(id)
const viewFile = (path: string) => { const viewFile = (path: string) => {
const encoded = base64URLEncode(path) const encoded = base64URLEncode(path)
window.open(`${serverAddr}/archive/v/${encoded}?token=${localStorage.getItem('token')}`) window.open(`${serverAddr}/archive/v/${encoded}?token=${localStorage.getItem('token')}`)
@@ -170,7 +168,7 @@ const DownloadsTableView: React.FC = () => {
<ButtonGroup> <ButtonGroup>
<IconButton <IconButton
size="small" size="small"
onClick={() => abort(download.id)} onClick={() => client.kill(download.id)}
> >
{download.progress.percentage === '-1' ? <DeleteIcon /> : <StopCircleIcon />} {download.progress.percentage === '-1' ? <DeleteIcon /> : <StopCircleIcon />}

View File

@@ -35,7 +35,7 @@ const Footer: React.FC = () => {
display: 'flex', gap: 1, justifyContent: 'space-between' display: 'flex', gap: 1, justifyContent: 'space-between'
}}> }}>
<div style={{ display: 'flex', gap: 4, alignItems: 'center' }}> <div style={{ display: 'flex', gap: 4, alignItems: 'center' }}>
<Chip label="RPC v3.0.9" variant="outlined" size="small" /> <Chip label="RPC v3.1.0" variant="outlined" size="small" />
<VersionIndicator /> <VersionIndicator />
</div> </div>
<div style={{ display: 'flex', gap: 4, 'alignItems': 'center' }}> <div style={{ display: 'flex', gap: 4, 'alignItems': 'center' }}>

View File

@@ -26,8 +26,6 @@ const HomeSpeedDial: React.FC<Props> = ({ onDownloadOpen, onEditorOpen }) => {
const { i18n } = useI18n() const { i18n } = useI18n()
const { client } = useRPC() const { client } = useRPC()
const abort = () => client.killAll()
return ( return (
<SpeedDial <SpeedDial
ariaLabel="Home speed dial" ariaLabel="Home speed dial"
@@ -47,7 +45,7 @@ const HomeSpeedDial: React.FC<Props> = ({ onDownloadOpen, onEditorOpen }) => {
<SpeedDialAction <SpeedDialAction
icon={<DeleteForeverIcon />} icon={<DeleteForeverIcon />}
tooltipTitle={i18n.t('abortAllButton')} tooltipTitle={i18n.t('abortAllButton')}
onClick={abort} onClick={() => client.killAll()}
/> />
<SpeedDialAction <SpeedDialAction
icon={<BuildCircleIcon />} icon={<BuildCircleIcon />}

View File

@@ -76,15 +76,14 @@ export type DirectoryEntry = {
name: string name: string
path: string path: string
size: number size: number
shaSum: string
modTime: string modTime: string
isVideo: boolean isVideo: boolean
isDirectory: boolean isDirectory: boolean
} }
export type DeleteRequest = Pick<DirectoryEntry, 'path' | 'shaSum'> export type DeleteRequest = Pick<DirectoryEntry, 'path'>
export type PlayRequest = Pick<DirectoryEntry, 'path'> export type PlayRequest = DeleteRequest
export type CustomTemplate = { export type CustomTemplate = {
id: string id: string

View File

@@ -113,7 +113,6 @@ export default function Downloaded() {
modTime: '', modTime: '',
name: '..', name: '..',
path: upperLevel, path: upperLevel,
shaSum: '',
size: 0, size: 0,
}, ...r.filter(f => f.name !== '')] }, ...r.filter(f => f.name !== '')]
: r.filter(f => f.name !== '') : r.filter(f => f.name !== '')
@@ -144,7 +143,6 @@ export default function Downloaded() {
method: 'POST', method: 'POST',
body: JSON.stringify({ body: JSON.stringify({
path: entry.path, path: entry.path,
shaSum: entry.shaSum,
}) })
}), }),
matchW( matchW(