Skip to content

Commit a74d2c2

Browse files
authored
Merge pull request #1456 from hackclub/rluodev/1454-hcb-allow-site-to-build-without-hcbs-stats-endpoint
remove need for hcb stats page for deploy
2 parents 11b71e5 + 40670ce commit a74d2c2

File tree

4 files changed

+46
-24
lines changed

4 files changed

+46
-24
lines changed

components/fiscal-sponsorship/first/stats.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ function formatMoney(amount) {
4343
}
4444

4545
const Stats = ({ stats }) => {
46+
if (stats.transactions_volume === undefined) {
47+
return null
48+
}
4649
const [balance, setBalance] = useState(0) // A formatted balance string, split by decimal
4750

4851
useEffect(() => {
@@ -64,7 +67,6 @@ const Stats = ({ stats }) => {
6467

6568
return () => observer.disconnect()
6669
}, [stats.transactions_volume])
67-
6870
return (
6971
<Box id="parent">
7072
<Flex sx={{ flexDirection: 'column', alignItems: 'center' }}>
@@ -103,11 +105,20 @@ const Stats = ({ stats }) => {
103105

104106
export async function getStaticProps(context) {
105107
const res = await fetch(`https://hcb.hackclub.com/stats`)
106-
const stats = await res.json()
107-
108-
return {
109-
props: {
110-
stats
108+
try {
109+
const stats = await res.json()
110+
return {
111+
props: {
112+
stats
113+
},
114+
revalidate: 10
115+
}
116+
} catch (e) {
117+
return {
118+
props: {
119+
stats: {}
120+
},
121+
revalidate: 10
111122
}
112123
}
113124
}

components/index/cards/hcb.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default function Bank({ data }) {
2020
color: 'snow'
2121
}}
2222
badge
23-
text={data[0]}
23+
text={data[0] === 'error' ? 'The coolest money thing' : data[0]}
2424
>
2525
<Heading
2626
variant="title"

pages/fiscal-sponsorship/first.js

+15-7
Original file line numberDiff line numberDiff line change
@@ -184,12 +184,20 @@ export default function First({ stats }) {
184184

185185
export async function getStaticProps(context) {
186186
const res = await fetch(`https://hcb.hackclub.com/stats`)
187-
const stats = await res.json()
188-
189-
return {
190-
props: {
191-
stats
192-
},
193-
revalidate: 10
187+
try {
188+
const stats = await res.json()
189+
return {
190+
props: {
191+
stats
192+
},
193+
revalidate: 60 * 60 // once an hour
194+
}
195+
} catch (e) {
196+
return {
197+
props: {
198+
stats: {}
199+
},
200+
revalidate: 60 * 60 // once an hour
201+
}
194202
}
195203
}

pages/index.js

+13-10
Original file line numberDiff line numberDiff line change
@@ -1221,17 +1221,20 @@ export async function getStaticProps() {
12211221

12221222
// HCB: get total raised
12231223
let bankData = []
1224-
let initialBankData = await fetch('https://hcb.hackclub.com/stats').then(r =>
1225-
r.json()
1226-
)
1227-
let raised = initialBankData.raised / 100
1224+
let initialBankData = await fetch('https://hcb.hackclub.com/stats')
1225+
try {
1226+
const bd = await initialBankData.json()
1227+
let raised = bd.raised / 100
12281228

1229-
bankData.push(
1230-
`💰 ${raised.toLocaleString('en-US', {
1231-
style: 'currency',
1232-
currency: 'USD'
1233-
})} raised`
1234-
)
1229+
bankData.push(
1230+
`💰 ${raised.toLocaleString('en-US', {
1231+
style: 'currency',
1232+
currency: 'USD'
1233+
})} raised`
1234+
)
1235+
} catch {
1236+
bankData.push('error')
1237+
}
12351238

12361239
// Slack: get total raised
12371240
const { Slack: Slacky } = require('./api/slack')

0 commit comments

Comments
 (0)