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

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

View File

@@ -6,15 +6,13 @@ import { useI18n } from '../hooks/useI18n'
import { useRPC } from '../hooks/useRPC'
import DownloadCard from './DownloadCard'
const DownloadsCardView: React.FC = () => {
const DownloadsGridView: React.FC = () => {
const downloads = useRecoilValue(activeDownloadsState)
const { i18n } = useI18n()
const { client } = useRPC()
const { pushMessage } = useToast()
const abort = (id: string) => client.kill(id)
return (
<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}>
<DownloadCard
download={download}
onStop={() => abort(download.id)}
onStop={() => client.kill(download.id)}
onCopy={() => pushMessage(i18n.t('clipboardAction'), 'info')}
/>
</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 { client } = useRPC()
const abort = (id: string) => client.kill(id)
const viewFile = (path: string) => {
const encoded = base64URLEncode(path)
window.open(`${serverAddr}/archive/v/${encoded}?token=${localStorage.getItem('token')}`)
@@ -170,7 +168,7 @@ const DownloadsTableView: React.FC = () => {
<ButtonGroup>
<IconButton
size="small"
onClick={() => abort(download.id)}
onClick={() => client.kill(download.id)}
>
{download.progress.percentage === '-1' ? <DeleteIcon /> : <StopCircleIcon />}

View File

@@ -35,7 +35,7 @@ const Footer: React.FC = () => {
display: 'flex', gap: 1, justifyContent: 'space-between'
}}>
<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 />
</div>
<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 { client } = useRPC()
const abort = () => client.killAll()
return (
<SpeedDial
ariaLabel="Home speed dial"
@@ -47,7 +45,7 @@ const HomeSpeedDial: React.FC<Props> = ({ onDownloadOpen, onEditorOpen }) => {
<SpeedDialAction
icon={<DeleteForeverIcon />}
tooltipTitle={i18n.t('abortAllButton')}
onClick={abort}
onClick={() => client.killAll()}
/>
<SpeedDialAction
icon={<BuildCircleIcon />}