mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-18 04:25:54 +08:00
fix: GitHub stars count sync not working (#20126)
This commit is contained in:
parent
fa80ef90d2
commit
210b9ebf56
@ -2,6 +2,11 @@
|
|||||||
import { useQuery } from '@tanstack/react-query'
|
import { useQuery } from '@tanstack/react-query'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import type { GithubRepo } from '@/models/common'
|
import type { GithubRepo } from '@/models/common'
|
||||||
|
import { RiLoader2Line } from '@remixicon/react'
|
||||||
|
|
||||||
|
const defaultData = {
|
||||||
|
stargazers_count: 98570,
|
||||||
|
}
|
||||||
|
|
||||||
const getStar = async () => {
|
const getStar = async () => {
|
||||||
const res = await fetch('https://api.github.com/repos/langgenius/dify')
|
const res = await fetch('https://api.github.com/repos/langgenius/dify')
|
||||||
@ -13,15 +18,21 @@ const getStar = async () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const GithubStar: FC<{ className: string }> = (props) => {
|
const GithubStar: FC<{ className: string }> = (props) => {
|
||||||
const { isFetching, data } = useQuery<GithubRepo>({
|
const { isFetching, isError, data } = useQuery<GithubRepo>({
|
||||||
queryKey: ['github-star'],
|
queryKey: ['github-star'],
|
||||||
queryFn: getStar,
|
queryFn: getStar,
|
||||||
enabled: process.env.NODE_ENV !== 'development',
|
enabled: process.env.NODE_ENV !== 'development',
|
||||||
initialData: { stargazers_count: 81204 },
|
retry: false,
|
||||||
|
placeholderData: defaultData,
|
||||||
})
|
})
|
||||||
|
|
||||||
if (isFetching)
|
if (isFetching)
|
||||||
return null
|
return <RiLoader2Line className='size-3 shrink-0 animate-spin text-text-tertiary' />
|
||||||
return <span {...props}>{data.stargazers_count.toLocaleString()}</span>
|
|
||||||
|
if (isError)
|
||||||
|
return <span {...props}>{defaultData.stargazers_count.toLocaleString()}</span>
|
||||||
|
|
||||||
|
return <span {...props}>{data?.stargazers_count.toLocaleString()}</span>
|
||||||
}
|
}
|
||||||
|
|
||||||
export default GithubStar
|
export default GithubStar
|
||||||
|
Loading…
x
Reference in New Issue
Block a user