diff --git a/tubearchivist/www/src/lib/getDownloads.ts b/tubearchivist/www/src/lib/getDownloads.ts old mode 100644 new mode 100755 index e610a90..560185d --- a/tubearchivist/www/src/lib/getDownloads.ts +++ b/tubearchivist/www/src/lib/getDownloads.ts @@ -1,9 +1,11 @@ import { Download } from "../types/download"; import { DownloadResponse } from "../types/download"; -import { TA_BASE_URL } from "./constants"; +import { getTAUrl } from "./constants"; -export const getDownloads = async (token: string): Promise => { - const response = await fetch(`${TA_BASE_URL}/api/download/`, { +const TA_BASE_URL = getTAUrl(); + +export const getDownloads = async (token: string, ignoredStatus: boolean): Promise => { + const response = await fetch(`${TA_BASE_URL.server}/api/download/?filter=${ignoredStatus ? 'ignore' : 'pending'}`, { headers: { Accept: "application/json", "Content-Type": "application/json", @@ -24,7 +26,7 @@ export const sendDownloads = async (token: string, input: string): Promise { } await queryClient.prefetchQuery(["downloads", session.ta_token.token], () => - getDownloads(session.ta_token.token) + getDownloads(session.ta_token.token, false) ); return { @@ -51,16 +52,17 @@ const Download: NextPage = () => { data: downloads, error, isLoading, + refetch, } = useQuery( ["downloads", session.ta_token.token], - () => getDownloads(session.ta_token.token), + () => getDownloads(session.ta_token.token, ignoredStatus), { enabled: !!session?.ta_token?.token, + refetchInterval: 1500, + refetchIntervalInBackground: false, } ); - var count = 0; - const [viewStyle, setViewStyle] = useState(downloads?.config?.default_view?.downloads); const [ignoredStatus, setIgnoredStatus] = useState(false); const [formHidden, setFormHidden] = useState(true); @@ -71,6 +73,7 @@ const Download: NextPage = () => { const handleSetIgnoredStatus = (selectedIgnoredStatus: IgnoredStatus) => { setIgnoredStatus(selectedIgnoredStatus); + refetch(); }; const handleSetFormHidden = (selectedFormHidden: FormHidden) => { @@ -142,31 +145,17 @@ const Download: NextPage = () => {
Show only ignored videos: - {ignoredStatus && -
- handleSetIgnoredStatus(false)} - type="checkbox" - checked - /> - -
- } - {!ignoredStatus && -
- handleSetIgnoredStatus(true)} - type="checkbox" - /> - -
- } +
+ handleSetIgnoredStatus(!ignoredStatus)} + type="checkbox" + checked={ignoredStatus} + /> + +
{
} - {downloads?.data?.forEach((video) => { - if ((video?.status == "ignore" && ignoredStatus) || (video?.status == "pending" && !ignoredStatus)) { - count++; - } - })} -

Total videos: {count} {!count &&

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

}

+

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 && downloads?.data?.map((video) => { - count++; - if ((video?.status == "ignore" && ignoredStatus) || (video?.status == "pending" && !ignoredStatus)) { return (
- video_thumb + video_thumb {ignoredStatus && ignored} {/* {% if show_ignored_only %} */} {/* ignored */} @@ -257,7 +239,6 @@ const Download: NextPage = () => {
); - } }) } {/* {% if results %} */}