Skip to content

Commit 9b8b2f5

Browse files
committed
✨ added github star counter
1 parent 1d308a9 commit 9b8b2f5

File tree

4 files changed

+60
-18
lines changed

4 files changed

+60
-18
lines changed

.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
NEXT_PUBLIC_POSTHOG_KEY=
2-
NEXT_PUBLIC_POSTHOG_HOST=
2+
NEXT_PUBLIC_POSTHOG_HOST=
3+
GITHUB_OAUTH_TOKEN=

src/components/AnimatedBadge.tsx

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,69 @@
11
'use client'
22

3+
import Counter from '@/showcase/components/text/text-ticker/Counter'
4+
import { useStarStore } from '@/store'
35
import { motion } from 'framer-motion'
4-
import { ChevronRight, Star } from 'lucide-react'
5-
import { useRouter } from 'next/navigation'
6+
import { Star } from 'lucide-react'
7+
import { useEffect } from 'react'
68

79
const AnimatedBadge = () => {
8-
const router = useRouter()
10+
const { stars, setStars } = useStarStore()
11+
12+
useEffect(() => {
13+
const fetchStars = async () => {
14+
if (stars > 100) return
15+
try {
16+
const response = await fetch(
17+
'https://api.github.com/repos/syntaxui/syntaxui',
18+
{
19+
headers: process.env.NEXT_PUBLIC_GITHUB_OAUTH_TOKEN
20+
? {
21+
Authorization: `Bearer ${process.env.NEXT_PUBLIC_GITHUB_OAUTH_TOKEN}`,
22+
'Content-Type': 'application/json',
23+
}
24+
: {},
25+
},
26+
)
27+
28+
if (response.ok) {
29+
const data = await response.json()
30+
setStars(data.stargazers_count || 100)
31+
}
32+
} catch (error) {
33+
console.error('Error fetching GitHub stars:', error)
34+
}
35+
}
36+
37+
fetchStars()
38+
}, [stars, setStars])
939

1040
return (
11-
<motion.button
41+
<motion.a
42+
href="https://github.com/syntaxUI/syntaxui"
43+
target="_blank"
44+
rel="noopener noreferrer"
1245
className="relative mb-8 inline-flex overflow-hidden rounded-full p-[1px] ring-1 ring-inset ring-gray-100/10"
1346
initial={{ opacity: 0, scale: 0.5 }}
1447
animate={{ opacity: 1, scale: 1 }}
1548
transition={{ duration: 0.5 }}
1649
whileHover={{ scale: 1.1 }}
1750
whileTap={{ scale: 0.9 }}
18-
onClick={() => {
19-
router.push('https://github.com/syntaxUI/syntaxui')
20-
}}
2151
>
2252
<span className="absolute inset-[-1000%] animate-discord-button bg-[conic-gradient(from_calc(var(--discord-button-angle)+60deg)_at_calc(50%+var(--discord-button-x))_50%,transparent_50%,#1d0005_98%,transparent_100%)]"></span>
2353
<span className="inline-flex items-center justify-center gap-2 rounded-full bg-black px-3 py-2 text-[12px] font-medium uppercase text-white backdrop-blur">
24-
<span>
54+
<span className="flex items-center gap-2">
2555
Star On Github
26-
<Star
27-
fill="#dba809"
28-
className="ml-2 inline-block h-4 w-4 text-yellow-500"
29-
/>
56+
<span className="h-4 w-[1px] bg-gray-200/50"></span>{' '}
57+
<span className="flex items-center tabular-nums">
58+
<Counter value={stars} />
59+
<Star
60+
fill="#dba809"
61+
className="ml-2 inline-block h-4 w-4 text-yellow-500"
62+
/>
63+
</span>
3064
</span>
3165
</span>
32-
</motion.button>
66+
</motion.a>
3367
)
3468
}
3569

src/components/ThemeToggle.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,6 @@ export function ThemeToggle() {
4343
setMounted(true)
4444
}, [setMounted])
4545

46-
useEffect(() => {
47-
console.log('Theme is', resolvedTheme)
48-
}, [resolvedTheme])
49-
5046
return (
5147
<button
5248
type="button"

src/store.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { create } from 'zustand'
2+
3+
interface StarStore {
4+
stars: number
5+
setStars: (count: number) => void
6+
}
7+
8+
export const useStarStore = create<StarStore>((set) => ({
9+
stars: 100,
10+
setStars: (count) => set({ stars: count }),
11+
}))

0 commit comments

Comments
 (0)