import React from "react";
import {
batchClearDownloads,
batchDeleteDownloads,
batchRetryDownloads,
clearCompletedDownloads,
deleteDownload,
deleteOnceDownloads,
killDownload,
restartDownload,
retryOnceDownloads
} from "../../api";
import {Link} from "react-router";
import {
APIButton,
DisableDownloadsToggle,
ErrorMessage,
formatFrequency,
isoDatetimeToElapsedPopup,
useTitle,
WROLModeMessage
} from "../Common";
import {
Button as SButton,
ButtonGroup,
Checkbox,
Label,
Loader,
PlaceholderLine,
TableBody,
TableCell,
TableFooter,
TableHeader,
TableHeaderCell,
TableRow
} from "semantic-ui-react";
import {Button, Header, Modal, Placeholder, Segment, Table} from "../Theme";
import {useDownloads} from "../../hooks/customHooks";
import {
EditArchiveDownloadForm,
EditChannelDownloadForm,
EditRSSDownloadForm,
EditScrapeFilesDownloadForm,
EditVideosDownloadForm,
EditZimDownloadForm
} from "../Download";
import {Downloaders} from "../Vars";
import {SortableTable} from "../SortableTable";
function ClearDownloadsButton({callback, selectedIds, clearSelection}) {
const hasSelection = selectedIds && selectedIds.length > 0;
async function localClearDownloads() {
try {
if (hasSelection) {
await batchClearDownloads(selectedIds);
if (clearSelection) clearSelection();
} else {
await clearCompletedDownloads();
}
} finally {
if (callback) {
callback()
}
}
}
const label = hasSelection ? `Clear (${selectedIds.length})` : 'Clear';
return <>
{label}
>
}
function RetryDownloadsButton({callback, selectedIds, clearSelection}) {
const hasSelection = selectedIds && selectedIds.length > 0;
async function localRetryOnce() {
try {
if (hasSelection) {
await batchRetryDownloads(selectedIds);
if (clearSelection) clearSelection();
} else {
await retryOnceDownloads();
}
} finally {
if (callback) {
callback()
}
}
}
const label = hasSelection ? `Retry (${selectedIds.length})` : 'Retry';
return {label}
}
function DeleteOnceDownloadsButton({callback, selectedIds, clearSelection}) {
const hasSelection = selectedIds && selectedIds.length > 0;
async function localDeleteOnce() {
try {
if (hasSelection) {
await batchDeleteDownloads(selectedIds);
if (clearSelection) clearSelection();
} else {
await deleteOnceDownloads();
}
} finally {
if (callback) {
callback()
}
}
}
const label = hasSelection ? `Delete (${selectedIds.length})` : 'Delete';
const confirmContent = hasSelection
? `Are you sure you want to delete ${selectedIds.length} download(s)?`
: 'Are you sure you want to delete all downloads? Some may be retried!';
return {label}
}
function RecurringDownloadRow({download, fetchDownloads, onDelete}) {
const [errorModalOpen, setErrorModalOpen] = React.useState(false);
const [editModalOpen, setEditModalOpen] = React.useState(false);
const handleRestart = async () => {
const {id} = download;
try {
await restartDownload(id);
} finally {
if (fetchDownloads) {
await fetchDownloads();
}
}
}
const handleEditOpen = () => setEditModalOpen(true);
const handleEditClose = () => setEditModalOpen(false);
const handleErrorOpen = () => setErrorModalOpen(true);
const handleErrorClose = () => setErrorModalOpen(false);
let {
url,
frequency,
last_successful_download,
status,
location,
next_download,
error,
downloader,
} = download;
const link = location ?
(text) => {text} :
(text) => {text};
const errorModal = }
>
Download Error
{error}
Close
;
const editButton =