)}
);
}
return onSelect(id)}
/>
{link(url)}
{completedAtCell}
{status === 'pending' && !download.progress ? : null}
{download.progress && }
{buttonCell}
{errorModal}
{editModal}
}
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 for everything except the URL, which takes what is left and truncates. See
* `.table-ellipsis` in App.css: under fixed layout a column with no width stated gets an
* equal share, which would give a checkbox as much room as a URL.
*
* The numbers are what the content needs, measured: a checkbox is 2.5em; "Completed At" is
* 9.5em on one line with its sort arrow, which is narrow enough to keep on a phone rather
* than wrapping it there; and Control is 9.5em, which holds the widest button group a row
* can have (a failed download shows delete, edit and retry).
*/
const tableHeaders = [
{
key: 'select',
text: 0 && selectedIds.length === downloads.length}
indeterminate={selectedIds.length > 0 && selectedIds.length < (downloads?.length || 0)}
onChange={toggleSelectAll}
/>,
sortBy: null,
width: '2.5em',
},
{key: 'url', text: 'URL', sortBy: i => i.url.toLowerCase()},
{key: 'completed_at', text: 'Completed At', sortBy: i => i.last_successful_download || '',
width: '9.5em'},
{key: 'control', text: 'Control', sortBy: null, width: '9.5em'},
];
const rowFunc = (download) => (
);
const footer =
;
if (downloads && downloads.length >= 1) {
return
} else if (downloads) {
return No downloads are scheduled.
} else if (downloads === undefined) {
return Unable to fetch downloads
}
return
}
export function RecurringDownloadsTable({downloads, fetchDownloads, onDelete}) {
if (downloads && downloads.length >= 1) {
return
{/* Widths in em, not percentages: what each of these columns has to hold is a
fixed amount of text or a fixed number of buttons, and a percentage of a
phone's width is not that. At 50% the URL column was 385px on a 540px
screen and pushed Next and Control off the edge. Only the URL is elastic
now -- it takes the remainder and truncates, which is its job.
"Download Frequency" is the one label too long to keep on one line on a
phone, so its width comes from `.col-frequency` in App.css, which widens at
the tablet breakpoint. The rest are sized to hold their label unwrapped at
any width. */}
URLDownload FrequencyCompleted AtNextControl
{downloads.map(i => {
return
})}
} else if (downloads) {
return No downloads are scheduled.
} else if (downloads === undefined) {
return Unable to fetch downloads
}
return
}
export function DownloadsPage() {
useTitle('Downloads');
const {onceDownloads, recurringDownloads, pendingOnceDownloads, fetchDownloads} = useDownloads();
const pendingOnceDownloadsSpan = pendingOnceDownloads > 0 ?
: null;
return <>
Downloads {pendingOnceDownloadsSpan}Recurring Downloads
>
}