From acadfe810e1dc676e69663d32f7d10a19c86c5a5 Mon Sep 17 00:00:00 2001 From: steven Date: Tue, 28 Mar 2023 16:54:32 +0800 Subject: [PATCH] chore: update github stars badge --- components/ChatView/Header.tsx | 9 ++---- components/GitHubStarBadge.tsx | 56 ++++++++++++++++++++++++++++++++++ 2 files changed, 58 insertions(+), 7 deletions(-) create mode 100644 components/GitHubStarBadge.tsx diff --git a/components/ChatView/Header.tsx b/components/ChatView/Header.tsx index 54c91a8..85d519b 100644 --- a/components/ChatView/Header.tsx +++ b/components/ChatView/Header.tsx @@ -1,6 +1,7 @@ import { useEffect } from "react"; import { useChatStore } from "@/store"; import Icon from "../Icon"; +import GitHubStarBadge from "../GitHubStarBadge"; interface Props { className?: string; @@ -27,13 +28,7 @@ const Header = (props: Props) => { {title} - - - + {title}
diff --git a/components/GitHubStarBadge.tsx b/components/GitHubStarBadge.tsx new file mode 100644 index 0000000..4dd5b95 --- /dev/null +++ b/components/GitHubStarBadge.tsx @@ -0,0 +1,56 @@ +import axios from "axios"; +import { useEffect, useState } from "react"; +import Icon from "./Icon"; + +interface Props { + className?: string; +} + +const GitHubStarBadge = (props: Props) => { + const { className } = props; + const [stars, setStars] = useState(0); + const [isRequesting, setIsRequesting] = useState(true); + + useEffect(() => { + const getRepoStarCount = async () => { + let starCount = 0; + try { + const { data } = await axios.get(`https://api.github.com/repos/bytebase/sqlchat`, { + headers: { + Accept: "application/vnd.github.v3.star+json", + Authorization: "", + }, + }); + starCount = data.stargazers_count as number; + } catch (error) { + // do nth + } + + setStars(starCount); + setIsRequesting(false); + }; + + getRepoStarCount(); + }, []); + + return ( + + + + Star + +
+ {isRequesting ? : stars} +
+
+ ); +}; + +export default GitHubStarBadge;