mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-17 18:35:19 +02:00
Add ai bot suggestions
This commit is contained in:
parent
2339a156c2
commit
f82764d186
1 changed files with 15 additions and 5 deletions
|
|
@ -1,3 +1,5 @@
|
|||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
|
||||
export const useGithubStars = () => {
|
||||
|
|
@ -9,6 +11,7 @@ export const useGithubStars = () => {
|
|||
const [error, setError] = useState<string | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const abortController = new AbortController();
|
||||
const getStars = async () => {
|
||||
try {
|
||||
if (!repo || !owner) {
|
||||
|
|
@ -17,7 +20,9 @@ export const useGithubStars = () => {
|
|||
|
||||
setError(null);
|
||||
|
||||
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`);
|
||||
const response = await fetch(`https://api.github.com/repos/${owner}/${repo}`, {
|
||||
signal: abortController.signal,
|
||||
});
|
||||
|
||||
if (!response.ok) {
|
||||
throw new Error(`Failed to fetch stars: ${response.statusText}`);
|
||||
|
|
@ -27,16 +32,21 @@ export const useGithubStars = () => {
|
|||
|
||||
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;
|
||||
if (err instanceof Error) {
|
||||
console.error("Error fetching stars:", err);
|
||||
setError(err.message);
|
||||
}
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
getStars();
|
||||
}, []);
|
||||
|
||||
return () => {
|
||||
abortController.abort();
|
||||
};
|
||||
}, [repo, owner]);
|
||||
|
||||
return {
|
||||
stars,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue