Skip to content

Commit 35533f3

Browse files
committed
Add github start count spinner
1 parent ae1702a commit 35533f3

File tree

4 files changed

+57
-8
lines changed

4 files changed

+57
-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: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,36 @@
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 res = await fetch(
17+
'https://api.github.com/repos/dev-five-git/devup-ui',
18+
{
19+
signal: abortController.signal,
20+
},
21+
)
22+
const data = await res.json()
23+
setStarCount(data.stargazers_count)
24+
} catch (error) {
25+
console.error(error)
26+
}
27+
}
28+
fetchStarCount()
29+
30+
return () => {
31+
abortController.abort()
32+
}
33+
}, [])
834

935
return (
1036
<Link
@@ -58,9 +84,18 @@ export default async function StarButton() {
5884
h="100%"
5985
px="16px"
6086
>
61-
<Text color="$primary" textAlign="center" typography="buttonLsemiB">
62-
{starCount}
63-
</Text>
87+
{starCount === null ? (
88+
<Image
89+
alt="Loading"
90+
animation="spin 1s linear infinite"
91+
boxSize="20px"
92+
src="/spinner.svg"
93+
/>
94+
) : (
95+
<Text color="$primary" textAlign="center" typography="buttonLsemiB">
96+
{starCount}
97+
</Text>
98+
)}
6499
</Center>
65100
</Flex>
66101
</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)