File tree Expand file tree Collapse file tree 6 files changed +465
-8
lines changed
Expand file tree Collapse file tree 6 files changed +465
-8
lines changed Original file line number Diff line number Diff line change 1818 "lib" : " @/lib" ,
1919 "hooks" : " @/hooks"
2020 },
21- "registries" : {}
21+ "registries" : {
22+ "@reui" : " https://reui.io/r/{name}.json"
23+ }
2224}
Original file line number Diff line number Diff line change 2121 "mdast-util-from-markdown" : " ^2.0.2" ,
2222 "mdast-util-gfm" : " ^3.1.0" ,
2323 "micromark-extension-gfm" : " ^3.0.0" ,
24+ "motion" : " ^12.23.24" ,
2425 "next-themes" : " ^0.4.6" ,
2526 "react" : " ^19.1.1" ,
2627 "react-code-block" : " ^1.1.3" ,
Original file line number Diff line number Diff line change 1+ import { useEffect , useState } from "react" ;
2+
3+ import { Button } from "../ui/button" ;
4+ import { GithubButton } from "../ui/github-button" ;
5+ import { AppLoading } from "./AppLoading" ;
6+ import { Github } from "lucide-react" ;
7+
8+ export function AppGitHubButton ( ) {
9+ const [ stars , setStars ] = useState < number | null > ( null ) ;
10+ const [ error , setError ] = useState < string | null > ( null ) ;
11+
12+ // Fetch repo data from GitHub API.
13+ useEffect ( ( ) => {
14+ async function fetchStars ( ) {
15+ try {
16+ const response = await fetch (
17+ "https://api.github.com/repos/LibreSplit/LibreSplit" ,
18+ {
19+ headers : { Accept : "application/vnd.github+json" } ,
20+ } ,
21+ ) ;
22+
23+ if ( ! response . ok )
24+ throw new Error ( `GitHub API error: ${ response . status } ` ) ;
25+
26+ const data = await response . json ( ) ;
27+ setStars ( data . stargazers_count ) ;
28+ } catch ( err ) {
29+ setError ( ( err as Error ) . message ) ;
30+ }
31+ }
32+
33+ fetchStars ( ) ;
34+ } , [ ] ) ;
35+
36+ // Show whilst API request loads.
37+ if ( stars == null ) {
38+ return < AppLoading /> ;
39+ }
40+
41+ // Show in the case of an error.
42+ if ( error ) {
43+ return (
44+ < Button >
45+ < a href = "https://github.com/LibreSplit/LibreSplit" >
46+ < Github />
47+ </ a >
48+ </ Button >
49+ ) ;
50+ }
51+
52+ // Show full component.
53+ return (
54+ < GithubButton
55+ repoUrl = "https://github.com/LibreSplit/LibreSplit"
56+ label = "GitHub"
57+ initialStars = { 0 }
58+ targetStars = { stars }
59+ />
60+ ) ;
61+ }
Original file line number Diff line number Diff line change 1- import { Button } from "../ui/button" ;
21import {
32 NavigationMenu ,
43 NavigationMenuItem ,
54 NavigationMenuLink ,
65 NavigationMenuList ,
76} from "../ui/navigation-menu" ;
7+ import { AppGitHubButton } from "./AppGitHubButton" ;
88import { AppThemeToggleButton } from "./AppThemeToggleButton" ;
9- import { Github } from "lucide-react" ;
109import { Link } from "react-router" ;
1110
1211export function AppNav ( ) {
@@ -57,11 +56,7 @@ function LeftNav() {
5756function RightNav ( ) {
5857 return (
5958 < div className = "flex items-center gap-2" >
60- < Button >
61- < a href = "https://github.com/wins1ey/LibreSplit" >
62- < Github />
63- </ a >
64- </ Button >
59+ < AppGitHubButton />
6560 < AppThemeToggleButton />
6661 </ div >
6762 ) ;
You can’t perform that action at this time.
0 commit comments