mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
display github starts on header and hamburger menu
This commit is contained in:
parent
8f4ccba59a
commit
525564bd82
3 changed files with 54 additions and 39 deletions
|
|
@ -1,42 +1,44 @@
|
|||
import { useCallback, useEffect, useState } from "react";
|
||||
import { apiClient } from "@/lib/api";
|
||||
|
||||
export const useGithubStarts = () => {
|
||||
const repo = process.env.NEXT_PUBLIC_GITHUB_REPO;
|
||||
const owner = process.env.NEXT_PUBLIC_GITHUB_OWNER;
|
||||
const token = process.env.NEXT_PUBLIC_GITHUB_TOKEN;
|
||||
const repo = process.env.NEXT_PUBLIC_GITHUB_REPO;
|
||||
const owner = process.env.NEXT_PUBLIC_GITHUB_OWNER;
|
||||
|
||||
const [starts, setStarts] = useState<number | null>(null);
|
||||
const [starts, setStarts] = useState<number | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const getStarts = async () => {
|
||||
try {
|
||||
if (!repo || !owner || !token) {
|
||||
throw new Error("Missing GitHub credentials");
|
||||
}
|
||||
const response = await apiClient.get<{ stargazers_count: number }>(
|
||||
`https://api.github.com/repos/${owner}/${repo}`,
|
||||
{
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
useEffect(() => {
|
||||
const getStarts = async () => {
|
||||
try {
|
||||
if (!repo || !owner) {
|
||||
throw new Error("Missing GitHub credentials");
|
||||
}
|
||||
|
||||
setStarts(response.stargazers_count);
|
||||
} catch (err) {
|
||||
console.error("Error fetching starts:", err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`);
|
||||
|
||||
getStarts();
|
||||
}, []);
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch starts: ${response.statusText}`);
|
||||
}
|
||||
|
||||
return {
|
||||
starts,
|
||||
compactFormat: Intl.NumberFormat("en-US", {
|
||||
notation: "compact",
|
||||
}).format(starts || 0),
|
||||
};
|
||||
const data = await response.json();
|
||||
|
||||
setStarts(data?.stargazers_count);
|
||||
} catch (err) {
|
||||
console.error("Error fetching starts:", err);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
getStarts();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
starts,
|
||||
loading,
|
||||
compactFormat: Intl.NumberFormat("en-US", {
|
||||
notation: "compact",
|
||||
}).format(starts || 0),
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue