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

fix: revert code, upgrade server #5250

Merged
merged 5 commits into from
May 25, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
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-beta.1",
"@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
Loading