mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-20 06:56:18 -05:00
* review: the 375px phone this fix had not been measured on Answers the five findings on #660. * Recurring's four fixed columns wanted 416px between them, so at 375px the URL column got exactly 0 and the table overflowed again -- the same bug as before, moved down from 540px. Widths are phone-first now, in col-* classes, widening at the tablet breakpoint. * The in-progress button in Completed At carried "5 MBps / 3m44s" -- 169-188px measured, against 124px of column. It shows the percent; the modal it opens already lists speed, ETA and bytes, and the full text is on the button's title. * The select column was 2.5em: 16.5px of content for a 22px checkbox, which hung into the URL column. 3em holds the checkbox and its padding. * The Cypress fixtures were a raw <table>, so tableLayout would read 'fixed' even with the selector that loses to Mantine -- the test could not fail for the reason it claimed. They mount SortableTable, Table.HeaderCell onSort and a real Checkbox now, and the header check measures the text rather than skipping cells with no element child. * Comments trimmed to what cannot be recovered from the code. Fixing the first surfaced one more: once URL became the small column, its own header overran -- "URL" and its arrow need 72px against 58 -- and a single word cannot wrap. A header is clipped by its column as a last resort. Measured at 375px: once 46/58/123/146, recurring 44/100/104/57/69, nothing overflowing. 69 suites / 1214 jest tests pass. The Cypress tests here are NOT verified: the component runner does not start in this repo (see the separate cypress investigation), so every layout claim above rests on direct measurement in Chrome, not on that suite. * review: the 375px phone this fix had not been measured on Answers the five findings on #660, and now runs against a component suite that can actually execute (#661). * Recurring's four fixed columns wanted 416px between them, so at 375px the URL got exactly 0 and the table overflowed -- the same bug as before, moved down from 540px. Widths are phone-first now, in col-* classes, widening at the tablet breakpoint. * The in-progress button in Completed At carried "5 MBps / 3m44s", 169-188px against 124px of column. It shows the percent; the modal it opens already lists speed, ETA and bytes, and the full text is on the button's title. * The select column was 2.5em: 16.5px of content for a 22px checkbox, which hung into the URL column. 3em holds the checkbox and its padding. * The fixtures were a raw <table>, so tableLayout read 'fixed' even with the selector that loses to Mantine -- the test could not fail for the reason it claimed. They mount SortableTable, Table.HeaderCell onSort and a real Checkbox now. * Comments trimmed to what cannot be recovered from the code. Two defects the restored suite caught, neither of them findable before it ran: * The elastic URL column ends up narrower than its own header -- "URL" and its arrow need 72px against 58 -- and one word cannot wrap, so the column clips. A sized column must fit its label; only the elastic one may clip. That is what the header test asserts, per kind of column, rather than measuring text and calling it the label: the first version measured the text alone, missed the sort arrow, and passed while the button overran by 14px. * Recurring's Control column was 4.5em, 70px of content for a 78px "Control". Sized for the word rather than the button it holds: 5.2em. At 375px: once 46/58/123/146, recurring 33/100/104/57/80, nothing overflowing and no sized header clipped. The URL column there is 33px -- the accepted trade for keeping every column on a phone. 336 component tests pass, 69 suites / 1214 jest tests pass, npm run build is clean. * review: a header assertion that stopped at the padding box Three findings on #662. * The sized-header check compared scrollWidth to clientWidth, which is the padding box, so a label could overflow its content box into the padding and pass -- the same class of miss the 4.5em Control failure was meant to close. It measures the label's longest word (plus the sort arrow, where there is one) against the content box now. That found two more columns tuned to their exact limit and clipping by a pixel: Download Frequency wanted 79.4px of a 78.1px box, Completed At 82.3 of 81.9. Every sized column now has margin over its own label. * SortableTable stopped applying `width`, leaving dead keys at the Tags and Zim call sites. Removed, so a column is sized one way. CollectionTable's `width` is NOT dead -- it converts sixteenths to percentages -- so Channels, Docs, Playlists and Archive keep theirs. * Comments trimmed again: the percent button, the header clip, the ButtonGroup rule and the Cypress helper. 336 component tests pass, 69 suites / 1214 jest tests pass. * ui: a phone header short enough to leave room for the URL Five full-length headers do not fit a phone. Sized so each held its own label, the recurring URL column came out 20px -- narrower than one character and its ellipsis, a column present but carrying nothing. A long header carries both forms and `.label-*` shows one: Freq and Done below the tablet breakpoint, Download Frequency and Completed At above it, where there is room. The mobile widths are sized for the short word. At 375px the URL column goes from 20px to 105px on the recurring table and 54px to 97px on the once table. Nothing overflows, nothing clips, and every column stays. 336 component tests pass, 69 suites / 1214 jest tests pass, npm run build is clean.
729 lines
25 KiB
JavaScript
729 lines
25 KiB
JavaScript
import React from "react";
|
|
import {
|
|
batchClearDownloads,
|
|
batchDeleteDownloads,
|
|
batchRetryDownloads,
|
|
clearCompletedDownloads,
|
|
deleteDownload,
|
|
deleteOnceDownloads,
|
|
killDownload,
|
|
restartDownload,
|
|
retryOnceDownloads
|
|
} from "../../api";
|
|
import {Link} from "react-router";
|
|
import {
|
|
APIButton,
|
|
CookiesLockedMessage,
|
|
DisableDownloadsToggle,
|
|
DailyLimitMessage,
|
|
DownloadWindowMessage,
|
|
ErrorMessage,
|
|
formatFrequency,
|
|
humanBandwidth,
|
|
humanFileSize,
|
|
isoDatetimeToElapsedPopup,
|
|
useLocalStorage,
|
|
useTitle,
|
|
WROLModeMessage
|
|
} from "../Common";
|
|
import {
|
|
Button,
|
|
ButtonGroup,
|
|
Checkbox,
|
|
Header,
|
|
IconButton,
|
|
Label,
|
|
Loader,
|
|
Modal,
|
|
Panel,
|
|
Placeholder,
|
|
Progress,
|
|
Table,
|
|
} from "../ui";
|
|
import {useDownloads} from "../../hooks/customHooks";
|
|
import {
|
|
EditArchiveDownloadForm,
|
|
EditChannelDownloadForm,
|
|
EditRSSDownloadForm,
|
|
EditScrapeFilesDownloadForm,
|
|
EditVideosDownloadForm,
|
|
EditZimDownloadForm
|
|
} from "../Download";
|
|
import {Downloaders} from "../Vars";
|
|
import {SortableTable} from "../SortableTable";
|
|
|
|
// A header too long for a phone. Both forms are rendered and `.label-*` in App.css shows
|
|
// one; the mobile column widths are sized for the short word.
|
|
const shortHeader = (short, full) => <>
|
|
<span className='label-short'>{short}</span>
|
|
<span className='label-long'>{full}</span>
|
|
</>;
|
|
|
|
function DownloadProgressModal({progress, url}) {
|
|
const [open, setOpen] = React.useState(false);
|
|
const [navColor] = useLocalStorage('nav_color', 'violet');
|
|
|
|
const speedText = humanBandwidth(progress.speed);
|
|
const etaText = progress.eta || '...';
|
|
// A percent: this button sits in a column sized for its header, and speed-and-ETA does not
|
|
// fit there. The modal it opens carries the detail, and `title` the full text.
|
|
const buttonLabel = Number.isFinite(progress.percent) ? `${Math.round(progress.percent)}%` : '...';
|
|
|
|
return <>
|
|
<Button size='small' onClick={() => setOpen(true)} style={{marginLeft: '0.5em'}}
|
|
title={`${speedText} / ${etaText}`}>
|
|
{buttonLabel}
|
|
</Button>
|
|
<Modal closeIcon open={open} onClose={() => setOpen(false)} size='fullscreen'>
|
|
<Modal.Header>Download Progress</Modal.Header>
|
|
<Modal.Content>
|
|
<Progress
|
|
percent={progress.percent}
|
|
color={navColor}
|
|
label={`${humanFileSize(progress.bytes_downloaded)} / ${humanFileSize(progress.total_bytes)}`}
|
|
/>
|
|
<Table>
|
|
<Table.Body>
|
|
<Table.Row>
|
|
<Table.Cell style={{fontWeight: 600}}>Speed</Table.Cell>
|
|
<Table.Cell>{speedText}</Table.Cell>
|
|
</Table.Row>
|
|
<Table.Row>
|
|
<Table.Cell style={{fontWeight: 600}}>ETA</Table.Cell>
|
|
<Table.Cell>{progress.eta || 'Calculating...'}</Table.Cell>
|
|
</Table.Row>
|
|
<Table.Row>
|
|
<Table.Cell style={{fontWeight: 600}}>Downloaded</Table.Cell>
|
|
<Table.Cell>{humanFileSize(progress.bytes_downloaded)} / {humanFileSize(progress.total_bytes)}</Table.Cell>
|
|
</Table.Row>
|
|
{url && <Table.Row>
|
|
<Table.Cell style={{fontWeight: 600}}>URL</Table.Cell>
|
|
<Table.Cell style={{wordBreak: 'break-all'}}>{url}</Table.Cell>
|
|
</Table.Row>}
|
|
</Table.Body>
|
|
</Table>
|
|
</Modal.Content>
|
|
<Modal.Actions>
|
|
<Button role='cancel' onClick={() => setOpen(false)}>Close</Button>
|
|
</Modal.Actions>
|
|
</Modal>
|
|
</>;
|
|
}
|
|
|
|
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 <>
|
|
<APIButton
|
|
onClick={localClearDownloads}
|
|
color='violet'
|
|
obeyWROLMode={true}
|
|
>{label}</APIButton>
|
|
</>
|
|
}
|
|
|
|
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 <APIButton
|
|
role='retry'
|
|
onClick={localRetryOnce}
|
|
obeyWROLMode={true}
|
|
>{label}</APIButton>
|
|
}
|
|
|
|
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 <APIButton
|
|
role='danger'
|
|
onClick={localDeleteOnce}
|
|
confirmContent={confirmContent}
|
|
confirmButton='Delete'
|
|
obeyWROLMode={true}
|
|
>{label}</APIButton>
|
|
}
|
|
|
|
|
|
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) => <Link to={location}>{text}</Link> :
|
|
(text) => <a href={url} target='_blank' rel='noopener noreferrer'>{text}</a>;
|
|
|
|
const errorModal = <Modal size='fullscreen'
|
|
closeIcon
|
|
onClose={handleErrorClose}
|
|
open={errorModalOpen}
|
|
>
|
|
<Modal.Header>Download Error</Modal.Header>
|
|
<Modal.Content>
|
|
<pre style={{overflowX: 'scroll'}}>{error}</pre>
|
|
</Modal.Content>
|
|
<Modal.Actions>
|
|
<Button role='cancel' onClick={handleErrorClose}>Close</Button>
|
|
</Modal.Actions>
|
|
</Modal>;
|
|
|
|
const errorTrigger = <IconButton icon='exclamation triangle' label='Download error' color='danger'
|
|
onClick={handleErrorOpen}/>;
|
|
|
|
const hideEdit = downloader === Downloaders.MapCatalog || downloader === Downloaders.MapExtract;
|
|
const editButton = hideEdit ? null :
|
|
<IconButton icon='edit' label='Edit download' onClick={handleEditOpen}/>;
|
|
|
|
const restartButton = <APIButton
|
|
role='retry'
|
|
icon='redo'
|
|
confirmContent='Are you sure you want to restart this download?'
|
|
confirmButton='Restart'
|
|
onClick={handleRestart}
|
|
obeyWROLMode={true}
|
|
/>;
|
|
|
|
// Show "now" if we have passed the next_download.
|
|
let next = 'now';
|
|
if (next_download && new Date() < new Date(next_download)) {
|
|
next = isoDatetimeToElapsedPopup(next_download);
|
|
}
|
|
|
|
const onSuccess = async () => {
|
|
if (fetchDownloads) {
|
|
await fetchDownloads();
|
|
}
|
|
handleEditClose();
|
|
}
|
|
|
|
const localOnDelete = async () => {
|
|
try {
|
|
await deleteDownload(download.id);
|
|
await onDelete();
|
|
} finally {
|
|
await fetchDownloads();
|
|
handleEditClose();
|
|
}
|
|
}
|
|
|
|
let editForm;
|
|
if (downloader === Downloaders.VideoChannel) {
|
|
editForm = <EditChannelDownloadForm
|
|
download={download}
|
|
onCancel={handleEditClose}
|
|
onSuccess={onSuccess}
|
|
onDelete={localOnDelete}
|
|
/>;
|
|
} else if (downloader === Downloaders.RSS) {
|
|
editForm = <EditRSSDownloadForm
|
|
download={download}
|
|
onDelete={localOnDelete}
|
|
onCancel={handleEditClose}
|
|
onSuccess={onSuccess}
|
|
/>;
|
|
} else if (downloader === Downloaders.KiwixCatalog) {
|
|
editForm = <EditZimDownloadForm
|
|
download={download}
|
|
onDelete={localOnDelete}
|
|
onCancel={handleEditClose}
|
|
onSuccess={onSuccess}
|
|
/>;
|
|
} else if (downloader === Downloaders.ScrapeHtml) {
|
|
editForm = <EditScrapeFilesDownloadForm
|
|
download={download}
|
|
onDelete={localOnDelete}
|
|
onCancel={handleEditClose}
|
|
onSuccess={onSuccess}
|
|
/>;
|
|
}
|
|
|
|
const editModal = <Modal size='large' closeIcon
|
|
open={editModalOpen}
|
|
onClose={handleEditClose}
|
|
>
|
|
<Modal.Header>Edit Download</Modal.Header>
|
|
<Modal.Content>
|
|
{editForm}
|
|
</Modal.Content>
|
|
</Modal>;
|
|
|
|
return <Table.Row failed={!!error && !download.progress}>
|
|
<Table.Cell className='column-ellipsis'>
|
|
{link(url)}
|
|
</Table.Cell>
|
|
<Table.Cell>{formatFrequency(frequency)}</Table.Cell>
|
|
<Table.Cell>
|
|
{last_successful_download && isoDatetimeToElapsedPopup(last_successful_download)}
|
|
{status === 'pending' && !download.progress && <Loader size='xs'/>}
|
|
{download.progress && <DownloadProgressModal progress={download.progress} url={download.url}/>}
|
|
</Table.Cell>
|
|
<Table.Cell>{next}</Table.Cell>
|
|
<Table.Cell>
|
|
{/* `justify-content` rather than the cell's `text-align: right`, which a flex row
|
|
does not answer to. These two are icon buttons and were sharing an edge. */}
|
|
<div className='wrolpi-button-row' style={{justifyContent: 'flex-end'}}>
|
|
{error && !download.progress && errorTrigger}
|
|
{editButton}
|
|
{restartButton}
|
|
</div>
|
|
</Table.Cell>
|
|
{errorModal}
|
|
{editModal}
|
|
</Table.Row>
|
|
}
|
|
|
|
function OnceDownloadRow({download, fetchDownloads, isSelected, onSelect}) {
|
|
const [editModalOpen, setEditModalOpen] = React.useState(false);
|
|
|
|
const {url, last_successful_download, status, location, error, downloader, settings, id, tag_names} = download;
|
|
const parentDownloadUrl = settings?.parent_download_url;
|
|
|
|
const handleDelete = async () => {
|
|
try {
|
|
await deleteDownload(id);
|
|
} finally {
|
|
await fetchDownloads();
|
|
}
|
|
};
|
|
|
|
const handleStop = async () => {
|
|
try {
|
|
await killDownload(id);
|
|
} finally {
|
|
await fetchDownloads();
|
|
}
|
|
};
|
|
|
|
const handleRestart = async () => {
|
|
try {
|
|
await restartDownload(id);
|
|
} finally {
|
|
await fetchDownloads();
|
|
}
|
|
};
|
|
|
|
const handleEditOpen = () => setEditModalOpen(true);
|
|
const handleEditClose = () => setEditModalOpen(false);
|
|
|
|
const handleEditSuccess = async () => {
|
|
await fetchDownloads();
|
|
handleEditClose();
|
|
};
|
|
|
|
// Open downloads (/download), or external links in an anchor.
|
|
const link = location && !location.startsWith('/download') ?
|
|
(text) => <Link to={location}>{text}</Link> :
|
|
(text) => <a href={location || url} target='_blank' rel='noopener noreferrer'>{text}</a>;
|
|
|
|
let completedAtCell = last_successful_download ? isoDatetimeToElapsedPopup(last_successful_download) : null;
|
|
let buttonCell = <Table.Cell/>;
|
|
if (status === 'pending' || status === 'new') {
|
|
buttonCell = (
|
|
<Table.Cell>
|
|
<ButtonGroup>
|
|
<APIButton
|
|
role='danger'
|
|
icon='stop'
|
|
onClick={handleStop}
|
|
confirmContent='Are you sure you want to stop this download? It will not be retried.'
|
|
confirmButton='Stop'
|
|
obeyWROLMode={true}
|
|
/>
|
|
{status === 'new' && (downloader === Downloaders.Video || downloader === Downloaders.Archive) && (
|
|
<IconButton
|
|
icon='edit'
|
|
label='Edit download'
|
|
color='blue'
|
|
onClick={handleEditOpen}
|
|
/>
|
|
)}
|
|
</ButtonGroup>
|
|
</Table.Cell>
|
|
);
|
|
} else if (status === 'failed' || status === 'deferred') {
|
|
buttonCell = (
|
|
<Table.Cell>
|
|
<ButtonGroup>
|
|
<APIButton
|
|
role='danger'
|
|
icon='trash'
|
|
onClick={handleDelete}
|
|
confirmContent='Are you sure you want to delete this download?'
|
|
confirmButton='Delete'
|
|
obeyWROLMode={true}
|
|
/>
|
|
{(downloader === Downloaders.Video || downloader === Downloaders.Archive) && status !== 'pending' && (
|
|
<IconButton
|
|
icon='edit'
|
|
label='Edit download'
|
|
color='blue'
|
|
onClick={handleEditOpen}
|
|
/>
|
|
)}
|
|
<APIButton
|
|
role='retry'
|
|
icon='redo'
|
|
confirmContent='Are you sure you want to restart this download?'
|
|
confirmButton='Start'
|
|
onClick={handleRestart}
|
|
obeyWROLMode={true}
|
|
/>
|
|
</ButtonGroup>
|
|
</Table.Cell>
|
|
);
|
|
} else if (status === 'complete' && location) {
|
|
buttonCell = (
|
|
<Table.Cell>
|
|
{link('View')}
|
|
</Table.Cell>
|
|
);
|
|
}
|
|
|
|
// Create edit modal for video or archive downloads
|
|
let editModal = null;
|
|
let errorModal = null;
|
|
const [errorModalOpen, setErrorModalOpen] = React.useState(false);
|
|
|
|
if (error && !download.progress) {
|
|
completedAtCell = (
|
|
<IconButton icon='exclamation triangle' label='Download error' color='danger'
|
|
onClick={() => setErrorModalOpen(true)}/>
|
|
)
|
|
errorModal = <Modal size='fullscreen'
|
|
closeIcon
|
|
open={errorModalOpen}
|
|
onClose={() => setErrorModalOpen(false)}
|
|
>
|
|
<Modal.Header>Download Error</Modal.Header>
|
|
<Modal.Content>
|
|
<pre style={{overflowX: 'scroll'}}>{error}</pre>
|
|
</Modal.Content>
|
|
</Modal>
|
|
}
|
|
|
|
if (downloader === Downloaders.Video) {
|
|
editModal = (
|
|
<Modal size='large'
|
|
closeIcon
|
|
open={editModalOpen}
|
|
onClose={handleEditClose}
|
|
>
|
|
<Modal.Header>Edit Video Download</Modal.Header>
|
|
<Modal.Content>
|
|
<EditVideosDownloadForm
|
|
download={{
|
|
urls: url,
|
|
settings: settings || {},
|
|
id: id,
|
|
tag_names: tag_names || []
|
|
}}
|
|
onCancel={handleEditClose}
|
|
onSuccess={handleEditSuccess}
|
|
onDelete={handleDelete}
|
|
/>
|
|
{parentDownloadUrl && (
|
|
<p style={{marginTop: '1em', color: 'var(--muted)'}}>
|
|
From: <a href={parentDownloadUrl} target='_blank' rel='noopener noreferrer'>
|
|
{parentDownloadUrl}
|
|
</a>
|
|
</p>
|
|
)}
|
|
</Modal.Content>
|
|
</Modal>
|
|
);
|
|
} else if (downloader === Downloaders.Archive) {
|
|
editModal = (
|
|
<Modal size='large'
|
|
closeIcon
|
|
open={editModalOpen}
|
|
onClose={handleEditClose}
|
|
>
|
|
<Modal.Header>Edit Archive Download</Modal.Header>
|
|
<Modal.Content>
|
|
<EditArchiveDownloadForm
|
|
download={{
|
|
urls: url,
|
|
tag_names: tag_names || [],
|
|
id: id
|
|
}}
|
|
onCancel={handleEditClose}
|
|
onSuccess={handleEditSuccess}
|
|
onDelete={handleDelete}
|
|
/>
|
|
{parentDownloadUrl && (
|
|
<p style={{marginTop: '1em', color: 'var(--muted)'}}>
|
|
From: <a href={parentDownloadUrl} target='_blank' rel='noopener noreferrer'>
|
|
{parentDownloadUrl}
|
|
</a>
|
|
</p>
|
|
)}
|
|
</Modal.Content>
|
|
</Modal>
|
|
);
|
|
}
|
|
|
|
return <Table.Row failed={status === 'failed' || status === 'deferred'}>
|
|
<Table.Cell>
|
|
<Checkbox
|
|
checked={isSelected}
|
|
onChange={() => onSelect(id)}
|
|
/>
|
|
</Table.Cell>
|
|
<Table.Cell className='column-ellipsis'>
|
|
{link(url)}
|
|
</Table.Cell>
|
|
<Table.Cell>
|
|
{completedAtCell}
|
|
{status === 'pending' && !download.progress ? <Loader size='xs'/> : null}
|
|
{download.progress && <DownloadProgressModal progress={download.progress} url={download.url}/>}
|
|
</Table.Cell>
|
|
{buttonCell}
|
|
{errorModal}
|
|
{editModal}
|
|
</Table.Row>
|
|
}
|
|
|
|
export function OnceDownloadsTable({downloads, fetchDownloads}) {
|
|
const [selectedIds, setSelectedIds] = React.useState([]);
|
|
|
|
// Clear selection when downloads change (e.g., after deletion)
|
|
React.useEffect(() => {
|
|
if (downloads) {
|
|
// Remove any selected IDs that no longer exist
|
|
const downloadIds = new Set(downloads.map(d => d.id));
|
|
setSelectedIds(prev => prev.filter(id => downloadIds.has(id)));
|
|
}
|
|
}, [downloads]);
|
|
|
|
const onSelect = (id) => {
|
|
if (selectedIds.includes(id)) {
|
|
setSelectedIds(selectedIds.filter(i => i !== id));
|
|
} else {
|
|
setSelectedIds([...selectedIds, id]);
|
|
}
|
|
};
|
|
|
|
const clearSelection = () => setSelectedIds([]);
|
|
|
|
const toggleSelectAll = () => {
|
|
if (downloads && selectedIds.length === downloads.length) {
|
|
setSelectedIds([]);
|
|
} else if (downloads) {
|
|
setSelectedIds(downloads.map(d => d.id));
|
|
}
|
|
};
|
|
|
|
// Widths come from the `col-*` classes in App.css, which change at the tablet breakpoint.
|
|
// Only the URL names none: it takes the remainder and truncates.
|
|
const tableHeaders = [
|
|
{
|
|
key: 'select',
|
|
text: <Checkbox
|
|
checked={downloads && downloads.length > 0 && selectedIds.length === downloads.length}
|
|
indeterminate={selectedIds.length > 0 && selectedIds.length < (downloads?.length || 0)}
|
|
onChange={toggleSelectAll}
|
|
/>,
|
|
sortBy: null,
|
|
className: 'col-select',
|
|
},
|
|
{key: 'url', text: 'URL', sortBy: i => i.url.toLowerCase()},
|
|
{key: 'completed_at', text: shortHeader('Done', 'Completed At'),
|
|
sortBy: i => i.last_successful_download || '', className: 'col-completed'},
|
|
{key: 'control', text: 'Control', sortBy: null, className: 'col-control-group'},
|
|
];
|
|
|
|
const rowFunc = (download) => (
|
|
<OnceDownloadRow
|
|
key={download.id}
|
|
download={download}
|
|
fetchDownloads={fetchDownloads}
|
|
isSelected={selectedIds.includes(download.id)}
|
|
onSelect={onSelect}
|
|
/>
|
|
);
|
|
|
|
const footer = <Table.Footer>
|
|
<Table.Row>
|
|
<Table.HeaderCell colSpan={4}>
|
|
<div className='wrolpi-button-row'>
|
|
<ClearDownloadsButton
|
|
callback={fetchDownloads}
|
|
selectedIds={selectedIds}
|
|
clearSelection={clearSelection}
|
|
/>
|
|
<RetryDownloadsButton
|
|
callback={fetchDownloads}
|
|
selectedIds={selectedIds}
|
|
clearSelection={clearSelection}
|
|
/>
|
|
<DeleteOnceDownloadsButton
|
|
callback={fetchDownloads}
|
|
selectedIds={selectedIds}
|
|
clearSelection={clearSelection}
|
|
/>
|
|
</div>
|
|
</Table.HeaderCell>
|
|
</Table.Row>
|
|
</Table.Footer>;
|
|
|
|
if (downloads && downloads.length >= 1) {
|
|
return <SortableTable
|
|
tableHeaders={tableHeaders}
|
|
data={downloads}
|
|
rowFunc={rowFunc}
|
|
rowKey='id'
|
|
footer={footer}
|
|
tableProps={{className: 'table-ellipsis'}}
|
|
/>
|
|
} else if (downloads) {
|
|
return <Panel>No downloads are scheduled.</Panel>
|
|
} else if (downloads === undefined) {
|
|
return <ErrorMessage>Unable to fetch downloads</ErrorMessage>
|
|
}
|
|
return <Placeholder lines={2}/>
|
|
}
|
|
|
|
export function RecurringDownloadsTable({downloads, fetchDownloads, onDelete}) {
|
|
if (downloads && downloads.length >= 1) {
|
|
return <Table className='table-ellipsis'>
|
|
<Table.Header>
|
|
{/* Widths come from the `col-*` classes in App.css, not percentages: what each
|
|
column holds is a fixed amount of text or a fixed number of buttons, and a
|
|
percentage of a phone's width is not that. Only the URL names none -- it
|
|
takes the remainder and truncates. */}
|
|
<Table.Row>
|
|
<Table.HeaderCell>URL</Table.HeaderCell>
|
|
<Table.HeaderCell className='col-frequency'>
|
|
{shortHeader('Freq', 'Download Frequency')}
|
|
</Table.HeaderCell>
|
|
<Table.HeaderCell className='col-completed-plain'>
|
|
{shortHeader('Done', 'Completed At')}
|
|
</Table.HeaderCell>
|
|
<Table.HeaderCell className='col-next'>Next</Table.HeaderCell>
|
|
<Table.HeaderCell className='col-control-row'
|
|
style={{textAlign: 'right'}}>Control</Table.HeaderCell>
|
|
</Table.Row>
|
|
</Table.Header>
|
|
<Table.Body>
|
|
{downloads.map(i => {
|
|
return <RecurringDownloadRow
|
|
key={i.id}
|
|
fetchDownloads={fetchDownloads}
|
|
download={i}
|
|
onDelete={onDelete}
|
|
/>
|
|
})}
|
|
</Table.Body>
|
|
</Table>
|
|
} else if (downloads) {
|
|
return <Panel>No downloads are scheduled.</Panel>
|
|
} else if (downloads === undefined) {
|
|
return <ErrorMessage>Unable to fetch downloads</ErrorMessage>
|
|
}
|
|
return <Placeholder lines={2}/>
|
|
}
|
|
|
|
export function DownloadsPage() {
|
|
useTitle('Downloads');
|
|
|
|
const {onceDownloads, recurringDownloads, pendingOnceDownloads, fetchDownloads} = useDownloads();
|
|
|
|
const pendingOnceDownloadsSpan = pendingOnceDownloads > 0 ?
|
|
<Label color='violet'>{pendingOnceDownloads}</Label>
|
|
: null;
|
|
|
|
return <>
|
|
<WROLModeMessage content='Downloads are disabled because WROL Mode is enabled.'/>
|
|
<DownloadWindowMessage/>
|
|
<DailyLimitMessage/>
|
|
<DisableDownloadsToggle/>
|
|
<CookiesLockedMessage/>
|
|
|
|
<Header as='h1'>Downloads {pendingOnceDownloadsSpan}</Header>
|
|
<OnceDownloadsTable downloads={onceDownloads} fetchDownloads={fetchDownloads}/>
|
|
|
|
<Header as='h1'>Recurring Downloads</Header>
|
|
<RecurringDownloadsTable downloads={recurringDownloads} fetchDownloads={fetchDownloads}/>
|
|
</>
|
|
}
|