Creating ClearFailedDownloads button.

This commit is contained in:
Roland 2022-04-01 16:45:59 -06:00
parent c4f511e469
commit 7ac3fbea2b
No known key found for this signature in database
GPG key ID: 9D6DBD3ACF11AB93
5 changed files with 92 additions and 7 deletions

View file

@ -532,7 +532,7 @@ export async function importMapFiles(paths) {
}
}
export async function clearDownloads() {
export async function clearCompletedDownloads() {
let response = await apiPost(`${API_URI}/download/clear_completed`);
if (response.status === 204) {
return null
@ -540,7 +540,21 @@ export async function clearDownloads() {
toast({
type: 'error',
title: 'Error!',
description: 'Could not clear downloads! See server logs.',
description: 'Could not clear completed downloads! See server logs.',
time: 5000,
});
}
}
export async function clearFailedDownloads() {
let response = await apiPost(`${API_URI}/download/clear_failed`);
if (response.status === 204) {
return null
} else {
toast({
type: 'error',
title: 'Error!',
description: 'Could not clear failed downloads! See server logs.',
time: 5000,
});
}

View file

@ -11,7 +11,15 @@ import {
Placeholder,
Table
} from "semantic-ui-react";
import {clearDownloads, getDownloads, getSettings, killDownload, postDownload, saveSettings} from "../api";
import {
clearCompletedDownloads,
clearFailedDownloads,
getDownloads,
getSettings,
killDownload,
postDownload,
saveSettings
} from "../api";
import TimezoneSelect from 'react-timezone-select';
import {
DisableDownloadsToggle,
@ -203,8 +211,11 @@ function ClearCompleteDownloads() {
async function localClearDownloads() {
setDisabled(true);
await clearDownloads();
setDisabled(false);
try {
await clearCompletedDownloads();
} finally {
setDisabled(false);
}
}
return <>
@ -216,6 +227,36 @@ function ClearCompleteDownloads() {
</>
}
function ClearFailedDownloads() {
const [open, setOpen] = React.useState(false);
const [disabled, setDisabled] = React.useState(false);
async function localDeleteFailed() {
setDisabled(true);
try {
await clearFailedDownloads();
} finally {
setDisabled(false);
setOpen(false);
}
}
return <>
<Button
onClick={() => setOpen(true)}
disabled={disabled}
color='red'
>Clear Failed</Button>
<Confirm
open={open}
content='Are you sure you want to delete failed downloads? They will not be retried.'
confirmButton='Delete'
onCancel={() => setOpen(false)}
onConfirm={localDeleteFailed}
/>
</>
}
class DownloadRow extends React.Component {
render() {
@ -408,6 +449,7 @@ class Downloads extends React.Component {
onceTable = (
<>
<ClearCompleteDownloads/>
<ClearFailedDownloads/>
<Table>
{stoppableHeader}
<Table.Body>