Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions apps/landing/public/spinner.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions apps/landing/src/app/StarButton.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
@keyframes spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}

50 changes: 43 additions & 7 deletions apps/landing/src/app/StarButton.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,37 @@
'use client'

import './StarButton.css'

import { Center, css, Flex, Image, Text } from '@devup-ui/react'
import Link from 'next/link'
import { useEffect, useState } from 'react'

export default function StarButton() {
const [starCount, setStarCount] = useState<number | null>(null)

export default async function StarButton() {
const res = await fetch('https://api.github.com/repos/dev-five-git/devup-ui')
const data = await res.json()
const starCount = data.stargazers_count
useEffect(() => {
const abortController = new AbortController()
const fetchStarCount = async () => {
try {
const data = await fetch(
'https://api.github.com/repos/dev-five-git/devup-ui',
{
signal: abortController.signal,
},
).then((res) => res.json())
setStarCount(data.stargazers_count)
} catch (error) {
console.error(error)
} finally {
setStarCount((prev) => (typeof prev === 'number' ? prev : -1))
}
}
fetchStarCount()

return () => {
abortController.abort()
}
}, [])

return (
<Link
Expand Down Expand Up @@ -58,9 +85,18 @@ export default async function StarButton() {
h="100%"
px="16px"
>
<Text color="$primary" textAlign="center" typography="buttonLsemiB">
{starCount}
</Text>
{starCount === null ? (
<Image
alt="Loading"
animation="spin 1s linear infinite"
boxSize="20px"
src="/spinner.svg"
/>
) : (
<Text color="$primary" textAlign="center" typography="buttonLsemiB">
{starCount}
</Text>
)}
</Center>
</Flex>
</Link>
Expand Down
2 changes: 1 addition & 1 deletion apps/landing/src/app/markdown.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@import url('https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css');
@import url(https://cdn.jsdelivr.net/gh/orioncactus/pretendard@v1.3.9/dist/web/static/pretendard.min.css);

table {
border-collapse: collapse;
Expand Down