mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-02 19:55:18 +02:00
add 'useGithubStarts' hook
This commit is contained in:
parent
5b957ec21c
commit
8007597b50
4 changed files with 48 additions and 13 deletions
37
surfsense_web/hooks/use-github-starts.ts
Normal file
37
surfsense_web/hooks/use-github-starts.ts
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
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 [starts, setStarts] = useState<number | null>(null);
|
||||
|
||||
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}`,
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
setStarts(response.stargazers_count);
|
||||
} catch (err) {
|
||||
console.error("Error fetching starts:", err);
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
getStarts();
|
||||
}, []);
|
||||
|
||||
return { starts };
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue