From a5c50fd6902032270dee5fb073202333ab663371 Mon Sep 17 00:00:00 2001 From: n8detar Date: Mon, 18 Apr 2022 09:00:53 -0700 Subject: [PATCH] Added invalid input message. --- tubearchivist/www/src/lib/getDownloads.ts | 3 ++- tubearchivist/www/src/pages/download.tsx | 23 ++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/tubearchivist/www/src/lib/getDownloads.ts b/tubearchivist/www/src/lib/getDownloads.ts index 04dde39..546ac95 100755 --- a/tubearchivist/www/src/lib/getDownloads.ts +++ b/tubearchivist/www/src/lib/getDownloads.ts @@ -37,7 +37,8 @@ export const sendDownloads = async (token: string, input: string): Promise { @@ -51,6 +52,7 @@ const Download: NextPage = () => { const [ignoredStatus, setIgnoredStatus] = useState(false); const [formHidden, setFormHidden] = useState(true); + const { data: downloads, @@ -62,13 +64,13 @@ const Download: NextPage = () => { () => getDownloads(session.ta_token.token, ignoredStatus), { enabled: !!session?.ta_token?.token, - // refetchInterval: 1500, - // refetchIntervalInBackground: false, + refetchInterval: 1500, + refetchIntervalInBackground: false, } ); const [viewStyle, setViewStyle] = useState(downloads?.config?.default_view?.downloads); - + const [errorMessage, setErrorMessage] = useState(false); const handleSetViewstyle = (selectedViewStyle: ViewStyle) => { setViewStyle(selectedViewStyle); @@ -85,10 +87,14 @@ const Download: NextPage = () => { setFormHidden(selectedFormHidden); }; + const handleSetErrorMessage = (selectedErrorMessage: ErrorMessage) => { + setErrorMessage(selectedErrorMessage); + }; + const addToDownloadQueue = event => { event.preventDefault(); - sendDownloads(session.ta_token.token, event.target.vid_url.value); - handleSetFormHidden(true); + sendDownloads(session.ta_token.token, event.target.vid_url.value).then((response) => !response.message ? handleSetErrorMessage(false) : handleSetErrorMessage(true)); + errorMessage ? handleSetFormHidden(false) : handleSetFormHidden(true); } return ( @@ -141,6 +147,9 @@ const Download: NextPage = () => {