frontend performance optimizations

This commit is contained in:
2023-11-02 10:42:59 +01:00
parent f49f072963
commit 1d9dabd397
4 changed files with 129 additions and 125 deletions

View File

@@ -55,7 +55,7 @@ export default function Layout() {
return (
<ThemeProvider theme={theme}>
<SocketSubscriber>
<SocketSubscriber />
<Helmet>
<title>
{settings.appTitle}
@@ -174,7 +174,6 @@ export default function Layout() {
</Box>
</Box>
<Toaster />
</SocketSubscriber>
</ThemeProvider>
)
}

View File

@@ -15,6 +15,7 @@ import {
Stack,
Typography
} from '@mui/material'
import { useCallback } from 'react'
import { RPCResult } from '../types'
import { ellipsis, formatSpeedMiB, mapProcessStatus, roundMiB } from '../utils'
@@ -34,11 +35,17 @@ const Resolution: React.FC<{ resolution?: string }> = ({ resolution }) => {
}
const DownloadCard: React.FC<Props> = ({ download, onStop, onCopy }) => {
const isCompleted = () => download.progress.percentage === '-1'
const isCompleted = useCallback(
() => download.progress.percentage === '-1',
[download.progress.percentage]
)
const percentageToNumber = () => isCompleted()
const percentageToNumber = useCallback(
() => isCompleted()
? 100
: Number(download.progress.percentage.replace('%', ''))
: Number(download.progress.percentage.replace('%', '')),
[download.progress.percentage, isCompleted]
)
return (
<Card>

View File

@@ -20,13 +20,11 @@ const DownloadsCardView: React.FC = () => {
{
downloads.map(download => (
<Grid item xs={4} sm={8} md={6} key={download.id}>
<>
<DownloadCard
download={download}
onStop={() => abort(download.id)}
onCopy={() => pushMessage(i18n.t('clipboardAction'), 'info')}
/>
</>
</Grid>
))
}

View File

@@ -25,7 +25,7 @@ export default function Splash() {
const { i18n } = useI18n()
const activeDownloads = useRecoilValue(activeDownloadsState)
if (!activeDownloads || activeDownloads.length !== 0) {
if (activeDownloads.length !== 0) {
return null
}