import type { GetServerSideProps, NextPage } from "next"; import { getSession, useSession } from "next-auth/react"; import { useState } from "react"; import { dehydrate, QueryClient, useQuery } from "react-query"; import { CustomHead } from "../components/CustomHead"; import { Layout } from "../components/Layout"; import NextImage from "next/image"; import { TA_BASE_URL } from "../lib/constants"; import { getDownloads } from "../lib/getDownloads"; import RescanIcon from "../images/icon-rescan.svg"; import DownloadIcon from "../images/icon-download.svg"; import AddIcon from "../images/icon-add.svg"; import GridViewIcon from "../images/icon-gridview.svg"; import ListViewIcon from "../images/icon-listview.svg"; type ViewStyle = "grid" | "list"; type IgnoredStatus = boolean; export const getServerSideProps: GetServerSideProps = async (context) => { const queryClient = new QueryClient(); const session = await getSession(context); if (!session) { return { redirect: { destination: "/auth/login", permanent: false, }, }; } await queryClient.prefetchQuery(["downloads", session.ta_token.token], () => getDownloads(session.ta_token.token) ); return { props: { dehydratedState: dehydrate(queryClient), session, }, }; }; const Download: NextPage = () => { const { data: session } = useSession(); const { data: downloads, error, isLoading, } = useQuery( ["downloads", session.ta_token.token], () => getDownloads(session.ta_token.token), { enabled: !!session?.ta_token?.token, } ); const [viewStyle, setViewStyle] = useState("grid"); const [ignoredStatus, setIgnoredStatus] = useState(false); const handleSetViewstyle = (selectedViewStyle: ViewStyle) => { setViewStyle(selectedViewStyle); }; const handleSetIgnoredStatus = (selectedIgnoredStatus: IgnoredStatus) => { setIgnoredStatus(selectedIgnoredStatus); }; return ( <>

Downloads

console.log("rescanPending()")} /> {/* rescan-icon */}

Rescan subscriptions

console.log("dlPending()")} /> {/* download-icon */}

Start download

console.log("showForm()")} />

Add to download queue

{/* {% csrf_token %} {{ subscribe_form }} */}
Show only ignored videos: {ignoredStatus &&
handleSetIgnoredStatus(false)} type="checkbox" checked />
} {!ignoredStatus &&
handleSetIgnoredStatus(true)} type="checkbox" />
}
handleSetViewstyle("grid")} /> {/* grid view */} handleSetViewstyle("list")} /> {/* list view */}
{ignoredStatus &&

Ignored from download

} {!ignoredStatus &&

Download queue

}

Total videos: {downloads?.data?.length} {!downloads?.data?.length &&

No videos queued for download. Press rescan subscriptions to check if there are any new videos.

}

{downloads.data && downloads?.data?.map((video) => { return (
video_thumb {ignoredStatus && ignored} {/* {% if show_ignored_only %} */} {/* ignored */} {!ignoredStatus && queued} {/* {% else %} */} {/* queued */} {/* {% endif %} */}

{video?.title}Video Title

{video?.channel?.channel_indexed && {video?.channel?.channel_name} Channel Name Link} {/* {% if video.source.channel_indexed %} */} {/* {{ video.source.channel_name }} */} {!video?.channel?.channel_indexed && {video?.channel?.channel_name} Channel Name No Link} {/* {% else %} */} {/* {{ video.source.channel_name }} */} {/* {% endif %} */}

Published: {video?.published} | Duration: {video?.player?.duration_str} | {video?.youtube_id}

{/*

Published: {{ video.source.published }} | Duration: {{ video.source.duration }} | {{ video.source.youtube_id }}

*/} {ignoredStatus &&
} {/* {% if show_ignored_only %} */} {/* */} {/* */} {!ignoredStatus &&
} {/* {% else %} */} {/* */} {/* */} {/* {% endif %} */}
); }) } {/* {% if results %} */} {/* {% for video in results %} */} {/*
*/} {/*
*/} {/* video_thumb */} {/* {% if show_ignored_only %} */} {/* ignored */} {/* {% else %} */} {/* queued */} {/* {% endif %} */} {/*
*/} {/*
*/} {/*

{{ video.source.title }}

*/} {/* {% if video.source.channel_indexed %} */} {/* {{ video.source.channel_name }} */} {/* {% else %} */} {/* {{ video.source.channel_name }} */} {/* {% endif %} */} {/*

Published: {{ video.source.published }} | Duration: {{ video.source.duration }} | {{ video.source.youtube_id }}

*/} {/* {% if show_ignored_only %} */} {/* */} {/* */} {/* {% else %} */} {/* */} {/* */} {/* {% endif %} */} {/*
*/} {/*
*/} {/* {% endfor %} */} {/* {% endif %} */}
{/* */}
); }; export default Download;