From 97d0d320023bb6269e9797f6e27d1ec060439ccd Mon Sep 17 00:00:00 2001 From: bitc0de Date: Wed, 17 Dec 2025 14:03:45 +0100 Subject: [PATCH] stars uploaded --- LICENSE | 21 ++++++++++++++++++++ components/Navbar.tsx | 46 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 65 insertions(+), 2 deletions(-) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..10a4a7d --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2025 bitc0de + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/components/Navbar.tsx b/components/Navbar.tsx index 9ef2cb7..2629f78 100644 --- a/components/Navbar.tsx +++ b/components/Navbar.tsx @@ -3,12 +3,52 @@ import { usePathname } from 'next/navigation' import Link from 'next/link' import { Home, ListMusic, Github, Star } from 'lucide-react' +import { useEffect, useState } from 'react' export default function Navbar() { const pathname = usePathname() + const [stars, setStars] = useState(null) const isActive = (path: string) => pathname === path + useEffect(() => { + const fetchStars = () => { + fetch('https://api.github.com/repos/bitc0de/bitify') + .then(res => res.json()) + .then(data => { + if (data.stargazers_count !== undefined) { + setStars(data.stargazers_count) + } + }) + .catch((err) => { + console.error('Error fetching stars:', err) + setStars(null) + }) + } + + fetchStars() + + // Refresh when user comes back to the tab + const handleVisibilityChange = () => { + if (document.visibilityState === 'visible') { + fetchStars() + } + } + + document.addEventListener('visibilitychange', handleVisibilityChange) + + return () => { + document.removeEventListener('visibilitychange', handleVisibilityChange) + } + }, []) + + const formatStars = (count: number) => { + if (count >= 1000) { + return `${(count / 1000).toFixed(1)}k` + } + return count.toString() + } + return (