Skip to content

Commit 874e930

Browse files
authored
Merge pull request #18 from LibreSplit/github
GitHub button redesign
2 parents dbcd2da + 98959ba commit 874e930

File tree

6 files changed

+465
-8
lines changed

6 files changed

+465
-8
lines changed

components.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,7 @@
1818
"lib": "@/lib",
1919
"hooks": "@/hooks"
2020
},
21-
"registries": {}
21+
"registries": {
22+
"@reui": "https://reui.io/r/{name}.json"
23+
}
2224
}

package-lock.json

Lines changed: 69 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
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",
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
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+
}

src/components/libresplit/AppNav.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
import { Button } from "../ui/button";
21
import {
32
NavigationMenu,
43
NavigationMenuItem,
54
NavigationMenuLink,
65
NavigationMenuList,
76
} from "../ui/navigation-menu";
7+
import { AppGitHubButton } from "./AppGitHubButton";
88
import { AppThemeToggleButton } from "./AppThemeToggleButton";
9-
import { Github } from "lucide-react";
109
import { Link } from "react-router";
1110

1211
export function AppNav() {
@@ -57,11 +56,7 @@ function LeftNav() {
5756
function 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
);

0 commit comments

Comments
 (0)