Skip to content

Commit 83f1b81

Browse files
authored
Merge pull request #245 from forestream/fix-github
Add github start count spinner
2 parents ae1702a + 5a0e47e commit 83f1b81

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

apps/landing/public/spinner.svg

Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@keyframes spin {
2+
from {
3+
transform: rotate(0deg);
4+
}
5+
to {
6+
transform: rotate(360deg);
7+
}
8+
}
9+

apps/landing/src/app/StarButton.tsx

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,37 @@
1+
'use client'
2+
3+
import './StarButton.css'
4+
15
import { Center, css, Flex, Image, Text } from '@devup-ui/react'
26
import Link from 'next/link'
7+
import { useEffect, useState } from 'react'
8+
9+
export default function StarButton() {
10+
const [starCount, setStarCount] = useState<number | null>(null)
311

4-
export default async function StarButton() {
5-
const res = await fetch('https://api.github.com/repos/dev-five-git/devup-ui')
6-
const data = await res.json()
7-
const starCount = data.stargazers_count
12+
useEffect(() => {
13+
const abortController = new AbortController()
14+
const fetchStarCount = async () => {
15+
try {
16+
const data = await fetch(
17+
'https://api.github.com/repos/dev-five-git/devup-ui',
18+
{
19+
signal: abortController.signal,
20+
},
21+
).then((res) => res.json())
22+
setStarCount(data.stargazers_count)
23+
} catch (error) {
24+
console.error(error)
25+
} finally {
26+
setStarCount((prev) => (typeof prev === 'number' ? prev : -1))
27+
}
28+
}
29+
fetchStarCount()
30+
31+
return () => {
32+
abortController.abort()
33+
}
34+
}, [])
835

936
return (
1037
<Link
@@ -58,9 +85,18 @@ export default async function StarButton() {
5885
h="100%"
5986
px="16px"
6087
>
61-
<Text color="$primary" textAlign="center" typography="buttonLsemiB">
62-
{starCount}
63-
</Text>
88+
{starCount === null ? (
89+
<Image
90+
alt="Loading"
91+
animation="spin 1s linear infinite"
92+
boxSize="20px"
93+
src="/spinner.svg"
94+
/>
95+
) : (
96+
<Text color="$primary" textAlign="center" typography="buttonLsemiB">
97+
{starCount}
98+
</Text>
99+
)}
64100
</Center>
65101
</Flex>
66102
</Link>

apps/landing/src/app/markdown.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@import url('https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard.min.css');
1+
@import url(https://cdn.jsdelivr.net/gh/orioncactus/[email protected]/dist/web/static/pretendard.min.css);
22

33
table {
44
border-collapse: collapse;

0 commit comments

Comments
 (0)