Skip to content

Commit

Permalink
fix: revert code, upgrade server (#5250)
Browse files Browse the repository at this point in the history
  • Loading branch information
yathomasi authored May 25, 2024
1 parent eda0349 commit 40bb83f
Show file tree
Hide file tree
Showing 4 changed files with 2,458 additions and 241 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
"dependencies": {
"@dvcorg/gatsby-theme-iterative": "0.3.14",
"@dvcorg/websites-server": "0.1.3",
"@dvcorg/websites-server": "0.2.0",
"@octokit/request": "8.1.6",
"@radix-ui/react-dialog": "1.0.5",
"@radix-ui/react-label": "2.0.2",
Expand Down
27 changes: 16 additions & 11 deletions src/gatsby/hooks/stars.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useEffect, useState } from 'react'
import { useStaticQuery, graphql } from 'gatsby'
import fetch from 'isomorphic-fetch'
import * as Sentry from '@sentry/gatsby'

export default function useStars(): number | null {
// Get the amount of stars from build time
Expand All @@ -13,21 +14,25 @@ export default function useStars(): number | null {
`).staticGithubData.stars

// Maintain an updatable state so we can update stars on delivery
const [stars, setStars] = useState(null)
const [stars, setStars] = useState(staticStars)

// Run an IIFE to update from the server on the client side.
useEffect(() => {
;(async (): Promise<void> => {
setStars(staticStars)
return
const res = await fetch(`/api/github/stars?repo=dvc`)
if (res.status === 200) {
const json = await res.json()
setStars(json.stars)
} else {
console.warn(
`Stars update response status was ${res.status}! Using static value.`
)
try {
const res = await fetch(`/api/github/stars?repo=dvc`)

if (res.status === 200) {
const json = await res.json()
setStars(json.stars)
} else {
Sentry.captureMessage(
`Stars update response status was ${res.status}! Using static value.`
)
setStars(staticStars)
}
} catch (error) {
Sentry.captureException(error)
setStars(staticStars)
}
})()
Expand Down
2 changes: 1 addition & 1 deletion src/gatsby/models/github/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ module.exports = {
type: 'StaticGithubData',
async resolve() {
const { GITHUB_TOKEN } = process.env
if (GITHUB_TOKEN && false) {
if (GITHUB_TOKEN) {
const stars = await getStars({ owner: 'iterative', repo: 'dvc' })
return { stars }
}
Expand Down
Loading

0 comments on commit 40bb83f

Please sign in to comment.