Fixed process not cleared after download.

Closes  #160
This commit is contained in:
2024-06-21 10:41:49 +02:00
parent 38683bfe85
commit 0daf36719b
6 changed files with 35 additions and 10 deletions

View File

@@ -4,6 +4,7 @@ import { activeDownloadsState } from '../atoms/downloads'
import { useToast } from '../hooks/toast'
import { useI18n } from '../hooks/useI18n'
import { useRPC } from '../hooks/useRPC'
import { ProcessStatus, RPCResult } from '../types'
import DownloadCard from './DownloadCard'
const DownloadsGridView: React.FC = () => {
@@ -13,6 +14,10 @@ const DownloadsGridView: React.FC = () => {
const { client } = useRPC()
const { pushMessage } = useToast()
const stop = (r: RPCResult) => r.progress.process_status === ProcessStatus.Completed
? client.clear(r.id)
: client.kill(r.id)
return (
<Grid container spacing={{ xs: 2, md: 2 }} columns={{ xs: 4, sm: 8, md: 12, xl: 12 }} pt={2}>
{
@@ -20,7 +25,7 @@ const DownloadsGridView: React.FC = () => {
<Grid item xs={4} sm={8} md={6} xl={4} key={download.id}>
<DownloadCard
download={download}
onStop={() => client.kill(download.id)}
onStop={() => stop(download)}
onCopy={() => pushMessage(i18n.t('clipboardAction'), 'info')}
/>
</Grid>

View File

@@ -24,7 +24,7 @@ import { useRecoilValue } from 'recoil'
import { activeDownloadsState } from '../atoms/downloads'
import { serverURL } from '../atoms/settings'
import { useRPC } from '../hooks/useRPC'
import { RPCResult } from '../types'
import { ProcessStatus, RPCResult } from '../types'
import { base64URLEncode, formatSize, formatSpeedMiB } from "../utils"
const columns = [
@@ -133,6 +133,11 @@ const DownloadsTableView: React.FC = () => {
window.open(`${serverAddr}/archive/d/${encoded}?token=${localStorage.getItem('token')}`)
}
const stop = (r: RPCResult) => r.progress.process_status === ProcessStatus.Completed
? client.clear(r.id)
: client.kill(r.id)
function rowContent(_index: number, download: RPCResult) {
return (
<>
@@ -168,7 +173,7 @@ const DownloadsTableView: React.FC = () => {
<ButtonGroup>
<IconButton
size="small"
onClick={() => client.kill(download.id)}
onClick={() => stop(download)}
>
{download.progress.percentage === '-1' ? <DeleteIcon /> : <StopCircleIcon />}