import { useState } from "react"; import { CustomHead } from "~/components/CustomHead"; import { Layout } from "~/components/Layout"; import AddIcon from "~/images/icon-add.svg"; import DownloadIcon from "~/images/icon-download.svg"; import GridViewIcon from "~/images/icon-gridview.svg"; import ListViewIcon from "~/images/icon-listview.svg"; import RescanIcon from "~/images/icon-rescan.svg"; import { sendDeleteAllQueuedIgnored, sendDeleteVideoQueuedIgnored, sendDownloads, sendMoveVideoQueuedIgnored, sendTasks, } from "../lib/getDownloads"; import type { Tasks } from "~/types/download"; type ViewStyle = "grid" | "list"; type IgnoredStatus = boolean; type FormHidden = boolean; type ErrorMessage = string; type PageNumber = number; const Download = () => { const [ignoredStatus, setIgnoredStatus] = useState(false); const [pageNumber, setPageNumber] = useState(1); const [formHidden, setFormHidden] = useState(true); const [viewStyle, setViewStyle] = useState( downloads?.config?.default_view?.downloads ); const [errorMessage, setErrorMessage] = useState(null); const handleSetViewstyle = (selectedViewStyle: ViewStyle) => { setViewStyle(selectedViewStyle); }; const handleSetIgnoredStatus = (selectedIgnoredStatus: IgnoredStatus) => { setIgnoredStatus(selectedIgnoredStatus); refetch(); handleSetPageNumber(1); }; const handleSetFormHidden = (selectedFormHidden: FormHidden) => { setFormHidden(selectedFormHidden); }; const handleSetErrorMessage = (selectedErrorMessage: ErrorMessage) => { setErrorMessage(selectedErrorMessage); }; const handleSetPageNumber = (selectedPageNumber: PageNumber) => { setPageNumber(selectedPageNumber); }; const addToDownloadQueue = (event) => { event.preventDefault(); sendDownloads(session.ta_token.token, event.target.vid_url.value) .then(() => { handleSetErrorMessage(null); handleSetFormHidden(true); }) .catch((error) => handleSetErrorMessage(error.message)); }; const handleMoveVideoQueuedIgnored = ( session: string, youtube_id: string, status: string ) => { sendMoveVideoQueuedIgnored(session, youtube_id, status) .then(() => { handleSetErrorMessage(null); }) .catch((error) => handleSetErrorMessage(error.message)); }; const handleDeleteVideoQueuedIgnored = ( session: string, youtube_id: string ) => { sendDeleteVideoQueuedIgnored(session, youtube_id) .then(() => { handleSetErrorMessage(null); }) .catch((error) => handleSetErrorMessage(error.message)); }; const handleDeleteAllQueuedIgnored = (session: string, filter: string) => { sendDeleteAllQueuedIgnored(session, filter) .then(() => { handleSetErrorMessage(null); }) .catch((error) => handleSetErrorMessage(error.message)); }; const handleSendTask = (session: string, task: Tasks) => { sendTasks(session, task) .then((response) => { if (response.success) { handleSetErrorMessage(null); } else { handleSetErrorMessage(`Error running task: ${response.task}.`); } }) .catch((error) => handleSetErrorMessage(error.message)); }; return ( <>

Downloads

{(error || !downloads?.data) && !isLoading && (

API Connection Error

)} {errorMessage && (

Failed to add downloads to the queue.

{errorMessage}

)} { //
//

Adding new videos to download queue.

//

Extracting lists

//

Progress: 0/0

//
} { //
//

Rescanning channels and playlists.

//

Looking for new videos.

//
} { //
//

Downloading: `VIDEO_TITLE`

//

processing

//

`DOWNLOADED_PERCENTAGE`% of `VIDEO_SIVE``VIDEO_SIZE_UNIT` at `DOWNLOAD_SPEED``DOWNLOAD_SPEED_UNIT` - time left: `DOWNLOAD_TIME_LEFT`

//

processing

//

Moving

//

Completed

//
}
{/* Appears when video is downloading */} {/*
console.log("stopQueue()")} /> console.log("killQueue()")} />
*/}
handleSendTask(session.ta_token.token, "rescan_pending") } /> {/* rescan-icon */}

Rescan subscriptions

handleSendTask(session.ta_token.token, "download_pending") } /> {/* download-icon */}

Start download

formHidden ? handleSetFormHidden(false) : handleSetFormHidden(true) } />

Add to download queue

{!formHidden && (