diff --git a/tubearchivist/www/src/lib/getDownloads.ts b/tubearchivist/www/src/lib/getDownloads.ts index 43155fe..e610a90 100644 --- a/tubearchivist/www/src/lib/getDownloads.ts +++ b/tubearchivist/www/src/lib/getDownloads.ts @@ -1,4 +1,5 @@ import { Download } from "../types/download"; +import { DownloadResponse } from "../types/download"; import { TA_BASE_URL } from "./constants"; export const getDownloads = async (token: string): Promise => { @@ -15,3 +16,26 @@ export const getDownloads = async (token: string): Promise => { } return response.json(); }; + +export const sendDownloads = async (token: string, input: string): Promise => { + var data = { + "data": [{ + "youtube_id": input, + "status": "pending" + }] + }; + const response = await fetch(`${TA_BASE_URL}/api/download/`, { + body: JSON.stringify(data), + headers: { + Accept: "application/json", + "Content-Type": "application/json", + Authorization: `Token ${token}`, + mode: "no-cors", + }, + method: "POST" + }); + if (!response.ok) { + throw new Error("Error adding content to the download queue."); + } + return response.json(); +}; diff --git a/tubearchivist/www/src/pages/download.tsx b/tubearchivist/www/src/pages/download.tsx index 499689e..e310841 100755 --- a/tubearchivist/www/src/pages/download.tsx +++ b/tubearchivist/www/src/pages/download.tsx @@ -7,6 +7,7 @@ import { Layout } from "../components/Layout"; import NextImage from "next/image"; import { TA_BASE_URL } from "../lib/constants"; import { getDownloads } from "../lib/getDownloads"; +import { sendDownloads } from "../lib/getDownloads"; import RescanIcon from "../images/icon-rescan.svg"; import DownloadIcon from "../images/icon-download.svg"; import AddIcon from "../images/icon-add.svg"; @@ -16,6 +17,8 @@ import ListViewIcon from "../images/icon-listview.svg"; type ViewStyle = "grid" | "list"; type IgnoredStatus = boolean; +type FormHidden = boolean; + export const getServerSideProps: GetServerSideProps = async (context) => { const queryClient = new QueryClient(); @@ -58,6 +61,7 @@ const Download: NextPage = () => { const [viewStyle, setViewStyle] = useState(downloads?.config?.default_view?.downloads); const [ignoredStatus, setIgnoredStatus] = useState(false); + const [formHidden, setFormHidden] = useState(true); const handleSetViewstyle = (selectedViewStyle: ViewStyle) => { setViewStyle(selectedViewStyle); @@ -67,6 +71,16 @@ const Download: NextPage = () => { setIgnoredStatus(selectedIgnoredStatus); }; + const handleSetFormHidden = (selectedFormHidden: FormHidden) => { + setFormHidden(selectedFormHidden); + }; + + const addToDownloadQueue = event => { + event.preventDefault(); + sendDownloads(session.ta_token.token, event.target.vid_url.value); + handleSetFormHidden(true); + } + return ( <> @@ -110,16 +124,17 @@ const Download: NextPage = () => { src={AddIcon} alt="add-icon" title="Add to download queue" - onClick={() => console.log("showForm()")} + onClick={() => formHidden ? handleSetFormHidden(false) : handleSetFormHidden(true)} />

Add to download queue

-
-
- {/* {% csrf_token %} - {{ subscribe_form }} */} - -
-
+ {!formHidden && +
+
+