From ebb22163ab7e59fe2bf11241d7ce9065fc4fca86 Mon Sep 17 00:00:00 2001 From: "rluo.dev" <34289582+rluodev@users.noreply.github.com> Date: Tue, 14 Jan 2025 18:02:04 -0500 Subject: [PATCH 1/2] remove need for hcb stats page for deploy --- components/fiscal-sponsorship/first/stats.js | 23 +++++++++++++++----- components/index/cards/hcb.js | 2 +- pages/fiscal-sponsorship/first.js | 23 ++++++++++++++------ pages/index.js | 23 +++++++++++--------- 4 files changed, 47 insertions(+), 24 deletions(-) diff --git a/components/fiscal-sponsorship/first/stats.js b/components/fiscal-sponsorship/first/stats.js index 163e11190..d193640db 100644 --- a/components/fiscal-sponsorship/first/stats.js +++ b/components/fiscal-sponsorship/first/stats.js @@ -43,6 +43,9 @@ function formatMoney(amount) { } const Stats = ({ stats }) => { + if (stats.transactions_volume === undefined) { + return null + } const [balance, setBalance] = useState(0) // A formatted balance string, split by decimal useEffect(() => { @@ -64,7 +67,6 @@ const Stats = ({ stats }) => { return () => observer.disconnect() }, [stats.transactions_volume]) - return ( @@ -103,11 +105,20 @@ const Stats = ({ stats }) => { export async function getStaticProps(context) { const res = await fetch(`https://hcb.hackclub.com/stats`) - const stats = await res.json() - - return { - props: { - stats + try { + const stats = await res.json() + return { + props: { + stats + }, + revalidate: 10 + } + } catch (e) { + return { + props: { + stats: {} + }, + revalidate: 10 } } } diff --git a/components/index/cards/hcb.js b/components/index/cards/hcb.js index 7262e1eb0..a0720b70e 100644 --- a/components/index/cards/hcb.js +++ b/components/index/cards/hcb.js @@ -20,7 +20,7 @@ export default function Bank({ data }) { color: 'snow' }} badge - text={data[0]} + text={data[0] === 'error' ? 'The coolest money thing' : data[0]} > - r.json() - ) - let raised = initialBankData.raised / 100 + let initialBankData = await fetch('https://hcb.hackclub.com/stats') + try { + const bd = await initialBankData.json() + let raised = bd.raised / 100 - bankData.push( - `💰 ${raised.toLocaleString('en-US', { - style: 'currency', - currency: 'USD' - })} raised` - ) + bankData.push( + `💰 ${raised.toLocaleString('en-US', { + style: 'currency', + currency: 'USD' + })} raised` + ) + } catch { + bankData.push('error') + } // Slack: get total raised const { Slack: Slacky } = require('./api/slack') From 3756168cc01d7347b11b75b689d3a6564b3fd422 Mon Sep 17 00:00:00 2001 From: Gary Tou Date: Tue, 21 Jan 2025 14:08:29 -0800 Subject: [PATCH 2/2] Update revalidate to be once an hour --- pages/fiscal-sponsorship/first.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/pages/fiscal-sponsorship/first.js b/pages/fiscal-sponsorship/first.js index d805a5af7..6cb509553 100644 --- a/pages/fiscal-sponsorship/first.js +++ b/pages/fiscal-sponsorship/first.js @@ -190,15 +190,14 @@ export async function getStaticProps(context) { props: { stats }, - revalidate: 10 + revalidate: 60 * 60 // once an hour } } catch (e) { return { props: { stats: {} }, - revalidate: 10 + revalidate: 60 * 60 // once an hour } } - }