import React, {useContext, useState} from "react"; import {clearCompletedDownloads, clearFailedDownloads, killDownload, postDownload} from "../../api"; import {Link} from "react-router-dom"; import { DisableDownloadsToggle, secondsToElapsedPopup, secondsToFrequency, textEllipsis, WROLModeMessage } from "../Common"; import { Button as SemanticButton, Confirm, Modal, PlaceholderLine, TableBody, TableCell, TableHeader, TableHeaderCell, TableRow } from "semantic-ui-react"; import {Button, Header, Icon, Placeholder, Table} from "../Theme"; import {ThemeContext} from "../../contexts/contexts"; import {useDownloads} from "../../hooks/customHooks"; function ClearCompleteDownloads({callback}) { const [disabled, setDisabled] = React.useState(false); async function localClearDownloads() { setDisabled(true); try { await clearCompletedDownloads(); } finally { setDisabled(false); if (callback) { callback() } } } return <> } function ClearFailedDownloads({callback}) { 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); if (callback) { callback() } } } return <> setOpen(false)} onConfirm={localDeleteFailed} /> } class DownloadRow extends React.Component { constructor(props) { super(props); this.state = { errorModalOpen: false, } } render() { let {url, frequency, last_successful_download, status, location, next_download, error} = this.props; const {errorModalOpen} = this.state; const link = location ? (text) => {text} : (text) => {text}; let positive = false; if (status === 'pending') { positive = true; } const errorModal = this.setState({errorModalOpen: false})} onOpen={() => this.setState({errorModalOpen: true})} open={errorModalOpen} trigger={ ); } else if (status === 'failed' || status === 'deferred') { negative = status === 'failed'; warning = status === 'deferred'; buttonCell = ( ); } else if (status === 'complete' && location) { buttonCell = ( {link('View')} ); } if (error) { completedAtCell = ( this.setState({errorModalOpen: false})} onOpen={() => this.setState({errorModalOpen: true})} open={errorModalOpen} trigger={ ) } return ( {link(textEllipsis(url, 50))} {completedAtCell} {buttonCell} ); } } export function Downloads() { const {t} = useContext(ThemeContext); const {onceDownloads, recurringDownloads, fetchDownloads} = useDownloads(); const tablePlaceholder = ; const stoppableHeader = ( URL Completed At Control ); const nonStoppableHeader = ( URL Download Frequency Completed At Next View ); let onceTable = tablePlaceholder; if (onceDownloads && onceDownloads.length === 0) { onceTable =

No downloads are scheduled.

} else if (onceDownloads) { onceTable = ( <> {stoppableHeader} {onceDownloads.map((i) => )}
); } let recurringTable = tablePlaceholder; if (recurringDownloads && recurringDownloads.length === 0) { recurringTable =

No recurring downloads are scheduled.

} else if (recurringDownloads) { recurringTable = {nonStoppableHeader} {recurringDownloads.map((i) => )}
; } return <>
Downloads
{onceTable}
Recurring Downloads
{recurringTable} }