From 7fc971ab79d4caed4e0f56c55198c83b3ca1ff57 Mon Sep 17 00:00:00 2001 From: Ryan Slobojan Date: Sun, 26 Sep 2021 19:05:02 -0400 Subject: [PATCH 1/3] Moved pass count from bottom of page to title for more visibility --- components/Form.tsx | 45 ++------------------------------------------- components/Page.tsx | 32 +++++++++++++++++++++++++++++++- 2 files changed, 33 insertions(+), 44 deletions(-) diff --git a/components/Form.tsx b/components/Form.tsx index 67bf46c..80f4461 100644 --- a/components/Form.tsx +++ b/components/Form.tsx @@ -39,7 +39,6 @@ function Form(): JSX.Element { const [loading, setLoading] = useState(false); - const [passCount, setPassCount] = useState(''); const [generated, setGenerated] = useState(false); // this flag represents the file has been used to generate a pass const [isDisabledAppleWallet, setIsDisabledAppleWallet] = useState(false); @@ -48,34 +47,6 @@ function Form(): JSX.Element { const hitcountHost = 'https://stats.vaccine-ontario.ca'; - useEffect(() => { - if (passCount.length == 0) { - getPassCount(); - } - }, []); - - const getPassCount = async () => { - const hitCount = await getHitCount(); - setPassCount(hitCount); - }; - - async function getHitCount() { - - try { - const request = `${hitcountHost}/nocount?url=pass.vaccine-ontario.ca`; - - let response = await fetch(request); - const counter = await response.text(); - - return Promise.resolve(counter); - - } catch (e) { - console.error(e); - return Promise.reject(e); - } - - } - // Check if there is a translation and replace message accordingly const setErrorMessage = (message: string) => { if (!message) { @@ -193,31 +164,22 @@ function Form(): JSX.Element { } async function incrementCount() { - try { if (typeof generated == undefined || !generated) { const request = `${hitcountHost}/count?url=pass.vaccine-ontario.ca`; - console.log(request); + //console.log(request); let response = await fetch(request); - console.log(request); + //console.log(response); - const counter = await response.text(); // response count is not used intentionally so it always goes up by 1 only even if the server has changed - - let newPasscount = Number(passCount) + 1; - console.log(counter); - setPassCount(counter); setGenerated(true); - console.log(`new PassCount = ${newPasscount}`); - } } catch (e) { console.error(e); return Promise.reject(e); } - } // Add Pass to wallet @@ -434,9 +396,6 @@ function Form(): JSX.Element { {verifierLink()} - {passCount && } - - {/* */} diff --git a/components/Page.tsx b/components/Page.tsx index 8b1dfbd..36689eb 100644 --- a/components/Page.tsx +++ b/components/Page.tsx @@ -10,11 +10,41 @@ interface PageProps { function Page(props: PageProps): JSX.Element { const { t } = useTranslation('common'); + const [passCount, setPassCount] = useState(''); + + useEffect(() => { + if (passCount.length == 0) { + getPassCount(); + } + }, []); + + const getPassCount = async () => { + const hitCount = await getHitCount(); + setPassCount(hitCount); + }; + + async function getHitCount() { + + try { + const request = `${hitcountHost}/nocount?url=pass.vaccine-ontario.ca`; + + let response = await fetch(request); + const counter = await response.text(); + + return Promise.resolve(counter); + + } catch (e) { + console.error(e); + return Promise.reject(e); + } + } + + const displayPassCount = (passCount? ` - ${passCount.toLocaleString()} receipts processed to date!` : ''); return (
- {t('common:title')} + {t('common:title')}{displayPassCount}