mirror of
https://github.com/System-End/site.git
synced 2026-04-19 16:28:21 +00:00
Use Jia API for counttoamillion thing (#435)
* Use Jia API for counttoamillion thing * COMMAS
This commit is contained in:
parent
a99674d139
commit
979e9a2fa9
3 changed files with 342 additions and 351 deletions
|
|
@ -5,5 +5,5 @@
|
|||
|
||||
export default async function fetcher(...args) {
|
||||
const res = await fetch(...args)
|
||||
return res.json()
|
||||
return await res.json()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
const withCommas = x => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
|
||||
// fetches the latest message in #counttoamillion and returns the current count
|
||||
export const getCount = async (req, res) => {
|
||||
const history = await fetch(
|
||||
`https://slack.com/api/conversations.history?token=${process.env.SLACK_LEGACY_TOKEN}&channel=CDJMS683D&limit=1&inclusive=true`
|
||||
)
|
||||
.then(r => r.json())
|
||||
.catch(err => console.err(`Error: ${err}`))
|
||||
const str = history.messages?.[0].text.split(' ')?.[0].replace(/[^0-9]/g, '')
|
||||
if (!str) return 'error'
|
||||
return withCommas(Number(str))
|
||||
}
|
||||
|
||||
const getCountEndpoint = (req, res) => getCount().then(v => res.send(v))
|
||||
|
||||
export default getCountEndpoint
|
||||
|
|
@ -10,20 +10,25 @@ import Stat from '../../components/stat'
|
|||
import Footer from '../../components/footer'
|
||||
import Header from '../../components/slack/header'
|
||||
import SlackEvents from '../../components/slack/slack-events'
|
||||
import { getCount } from '../../pages/api/channels/count-to-a-million'
|
||||
import { formatted, thousands } from '../../lib/members'
|
||||
import useSWR from 'swr'
|
||||
import fetcher from '../../lib/fetcher'
|
||||
|
||||
const zoomSlide = keyframes({
|
||||
from: { backgroundPosition: '-32px bottom' },
|
||||
to: { backgroundPosition: '32px bottom' }
|
||||
})
|
||||
|
||||
export async function getStaticProps() {
|
||||
const millionCount = (await getCount()) || null
|
||||
return { props: { millionCount }, revalidate: 1 }
|
||||
}
|
||||
const withCommas = x => x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
|
||||
|
||||
const SlackPage = ({ millionCount }) => (
|
||||
const SlackPage = () => {
|
||||
const { data: millionCount } = useSWR(
|
||||
'https://jia.haas.hackclub.com/api/currentNumber',
|
||||
fetcher,
|
||||
{ refreshInterval: 1000 }
|
||||
)
|
||||
|
||||
return (
|
||||
<>
|
||||
<Meta
|
||||
as={Head}
|
||||
|
|
@ -102,7 +107,8 @@ const SlackPage = ({ millionCount }) => (
|
|||
top: 2,
|
||||
right: 2,
|
||||
fill: 'white',
|
||||
transition: 'transform 0.25s ease-in-out, opacity 0.25s ease-in-out'
|
||||
transition:
|
||||
'transform 0.25s ease-in-out, opacity 0.25s ease-in-out'
|
||||
},
|
||||
h3: {
|
||||
variant: 'text.headline',
|
||||
|
|
@ -192,7 +198,7 @@ const SlackPage = ({ millionCount }) => (
|
|||
as="span"
|
||||
sx={{ ml: [2, 0], mt: [0, 2], px: [2, 0], py: [0, 2] }}
|
||||
>
|
||||
{millionCount}
|
||||
{millionCount ? withCommas(millionCount.number) : '???'}
|
||||
</Badge>
|
||||
!
|
||||
</Text>
|
||||
|
|
@ -299,7 +305,8 @@ const SlackPage = ({ millionCount }) => (
|
|||
top: 2,
|
||||
right: 2,
|
||||
fill: 'white',
|
||||
transition: 'transform 0.25s ease-in-out, opacity 0.25s ease-in-out'
|
||||
transition:
|
||||
'transform 0.25s ease-in-out, opacity 0.25s ease-in-out'
|
||||
}
|
||||
}}
|
||||
>
|
||||
|
|
@ -385,5 +392,6 @@ const SlackPage = ({ millionCount }) => (
|
|||
<Footer />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default SlackPage
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue