mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 17:26:23 +02:00
Add ai bot suggestions
This commit is contained in:
parent
525564bd82
commit
2339a156c2
4 changed files with 31 additions and 20 deletions
49
surfsense_web/hooks/use-github-stars.ts
Normal file
49
surfsense_web/hooks/use-github-stars.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import { useEffect, useState } from "react";
|
||||
|
||||
export const useGithubStars = () => {
|
||||
const repo = process.env.NEXT_PUBLIC_GITHUB_REPO;
|
||||
const owner = process.env.NEXT_PUBLIC_GITHUB_OWNER;
|
||||
|
||||
const [stars, setStars] = useState<number | null>(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const getStars = async () => {
|
||||
try {
|
||||
if (!repo || !owner) {
|
||||
throw new Error("Missing GitHub credentials");
|
||||
}
|
||||
|
||||
setError(null);
|
||||
|
||||
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`);
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch stars: ${response.statusText}`);
|
||||
}
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
setStars(data?.stargazers_count);
|
||||
} catch (err) {
|
||||
console.error("Error fetching stars:", err);
|
||||
setError(err instanceof Error ? err.message : `Failed to fetch stars ${err}`);
|
||||
throw err;
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
getStars();
|
||||
}, []);
|
||||
|
||||
return {
|
||||
stars,
|
||||
loading,
|
||||
error,
|
||||
compactFormat: Intl.NumberFormat("en-US", {
|
||||
notation: "compact",
|
||||
}).format(stars || 0),
|
||||
};
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue