import React from "react"; import { clearCompletedDownloads, deleteDownload, deleteOnceDownloads, killDownload, putDownload, restartDownload, retryOnceDownloads } from "../../api"; import {Link} from "react-router-dom"; import { APIButton, DisableDownloadsToggle, ErrorMessage, frequencyOptions, isoDatetimeToElapsedPopup, secondsToFrequency, useTitle, validURL, WROLModeMessage } from "../Common"; import { Button as SButton, Dimmer, Dropdown, Grid, Label, Loader, PlaceholderLine, TableBody, TableCell, TableFooter, TableHeader, TableHeaderCell, TableRow } from "semantic-ui-react"; import { Button, Form, FormField, FormInput, Header, Modal, ModalActions, ModalContent, ModalHeader, Placeholder, Segment, Table } from "../Theme"; import {useDownloads, useWROLMode} from "../../hooks/customHooks"; import {toast} from "react-semantic-toasts-2"; import {ChannelDownloadForm} from "../Channels"; function ClearDownloadsButton({callback}) { async function localClearDownloads() { try { await clearCompletedDownloads(); } finally { if (callback) { callback() } } } return <> Clear } function RetryDownloadsButton({callback}) { async function localRetryOnce() { try { await retryOnceDownloads(); } finally { if (callback) { callback() } } } return Retry } function DeleteOnceDownloadsButton({callback}) { async function localDeleteOnce() { try { await deleteOnceDownloads(); } finally { if (callback) { callback() } } } return Delete } export function DownloadEditForm({afterSave, closeModal, download}) { const [state, setState] = React.useState({ url: download.url || '', frequency: download.frequency, excluded_urls: download.settings ? download.settings.excluded_urls : '', destination: download.settings ? download.settings.destination : '', }) const [disabled, setDisabled] = React.useState(useWROLMode()); const [loading, setLoading] = React.useState(false); const [urlValid, setUrlValid] = React.useState(true); const handleInputChange = (e, {name, value}) => { if (e) { e.preventDefault(); } if (name === 'url') { setUrlValid(validURL(value)); } setState({...state, [name]: value}); } const handleSubmit = async () => { setLoading(true); setDisabled(true); try { const response = await putDownload( [state.url], download.id, download.downloader, download.sub_downloader, state.frequency, state.excluded_urls, ); if (!response.ok) { throw 'Updating download failed'; } if (afterSave) { afterSave(); } } finally { setLoading(false); setDisabled(false); } } const handleClose = (e) => { if (e) e.preventDefault(); closeModal(); } const handleDelete = async () => { await deleteDownload(download.id); if (afterSave) { afterSave(); } if (closeModal) { closeModal(); } }; const deleteDownloadButton = Delete; return
{loading && } {deleteDownloadButton}
} class RecurringDownloadRow extends React.Component { constructor(props) { super(props); this.state = { errorModalOpen: false, editModalOpen: false, } } handleRestart = async () => { const {id} = this.props; try { await restartDownload(id); } finally { if (this.props.fetchDownloads) { this.props.fetchDownloads(); } } } render() { let { url, frequency, last_successful_download, status, location, next_download, error, downloader, } = this.props; const {errorModalOpen} = this.state; const link = location ? (text) => {text} : (text) => {text}; const errorModal = this.setState({errorModalOpen: false})} onOpen={() => this.setState({errorModalOpen: true})} open={errorModalOpen} trigger={