Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove need for hcb stats page for deploy #1456

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 17 additions & 6 deletions components/fiscal-sponsorship/first/stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -64,7 +67,6 @@ const Stats = ({ stats }) => {

return () => observer.disconnect()
}, [stats.transactions_volume])

return (
<Box id="parent">
<Flex sx={{ flexDirection: 'column', alignItems: 'center' }}>
Expand Down Expand Up @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good call on the revalidate for get static props.

instead of every 10 seconds. maybe we do once an hour? or even once a day? these numbers don't change that quickly.

}
} catch (e) {
return {
props: {
stats: {}
},
revalidate: 10
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion components/index/cards/hcb.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]}
>
<Heading
variant="title"
Expand Down
23 changes: 16 additions & 7 deletions pages/fiscal-sponsorship/first.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,21 @@ export default function First({ stats }) {

export async function getStaticProps(context) {
const res = await fetch(`https://hcb.hackclub.com/stats`)
const stats = await res.json()

return {
props: {
stats
},
revalidate: 10
try {
const stats = await res.json()
return {
props: {
stats
},
revalidate: 10
}
} catch (e) {
return {
props: {
stats: {}
},
revalidate: 10
}
}

}
23 changes: 13 additions & 10 deletions pages/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1221,17 +1221,20 @@ export async function getStaticProps() {

// HCB: get total raised
let bankData = []
let initialBankData = await fetch('https://hcb.hackclub.com/stats').then(r =>
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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if we pushed nothing? then in the card, we could replace:

data[0] === 'error' ? 'The coolest money thing' : data[0]

with

data[0] || 'The coolest money thing'

}

// Slack: get total raised
const { Slack: Slacky } = require('./api/slack')
Expand Down
Loading