mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-05-19 18:45:15 +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";
|
import { useEffect, useState } from "react";
|
||||||
|
|
||||||
export const useGithubStars = () => {
|
export const useGithubStars = () => {
|
||||||
|
|
@ -9,6 +11,7 @@ export const useGithubStars = () => {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
const abortController = new AbortController();
|
||||||
const getStars = async () => {
|
const getStars = async () => {
|
||||||
try {
|
try {
|
||||||
if (!repo || !owner) {
|
if (!repo || !owner) {
|
||||||
|
|
@ -17,7 +20,9 @@ export const useGithubStars = () => {
|
||||||
|
|
||||||
setError(null);
|
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) {
|
if (!response.ok) {
|
||||||
throw new Error(`Failed to fetch stars: ${response.statusText}`);
|
throw new Error(`Failed to fetch stars: ${response.statusText}`);
|
||||||
|
|
@ -27,16 +32,21 @@ export const useGithubStars = () => {
|
||||||
|
|
||||||
setStars(data?.stargazers_count);
|
setStars(data?.stargazers_count);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error("Error fetching stars:", err);
|
if (err instanceof Error) {
|
||||||
setError(err instanceof Error ? err.message : `Failed to fetch stars ${err}`);
|
console.error("Error fetching stars:", err);
|
||||||
throw err;
|
setError(err.message);
|
||||||
|
}
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
getStars();
|
getStars();
|
||||||
}, []);
|
|
||||||
|
return () => {
|
||||||
|
abortController.abort();
|
||||||
|
};
|
||||||
|
}, [repo, owner]);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
stars,
|
stars,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue