(props: Props)
| 7 | } |
| 8 | |
| 9 | const GitHubStarBadge = (props: Props) => { |
| 10 | const { className } = props; |
| 11 | const [stars, setStars] = useState(0); |
| 12 | const [isRequesting, setIsRequesting] = useState(true); |
| 13 | |
| 14 | useEffect(() => { |
| 15 | const getRepoStarCount = async () => { |
| 16 | let starCount = 0; |
| 17 | try { |
| 18 | const { data } = await axios.get(`https://api.github.com/repos/sqlchat/sqlchat`, { |
| 19 | headers: { |
| 20 | Accept: "application/vnd.github.v3.star+json", |
| 21 | Authorization: "", |
| 22 | }, |
| 23 | }); |
| 24 | starCount = data.stargazers_count as number; |
| 25 | } catch (error) { |
| 26 | // do nth |
| 27 | } |
| 28 | |
| 29 | setStars(starCount); |
| 30 | setIsRequesting(false); |
| 31 | }; |
| 32 | |
| 33 | getRepoStarCount(); |
| 34 | }, []); |
| 35 | |
| 36 | return ( |
| 37 | <a |
| 38 | className={`${ |
| 39 | className || "" |
| 40 | } border dark:border-zinc-600 rounded flex flex-row justify-start items-center text-black dark:text-gray-300 text-xs bg-white dark:bg-zinc-800 shadow-inner overflow-clip hover:opacity-80`} |
| 41 | href="https://github.com/sqlchat/sqlchat" |
| 42 | target="_blank" |
| 43 | aria-label="Star SQL Chat on GitHub" |
| 44 | > |
| 45 | <span className="pr-1 pl-1.5 py-0.5 h-full flex flex-row justify-center items-center bg-gray-100 dark:bg-zinc-700 border-r dark:border-zinc-600 font-medium"> |
| 46 | <Icon.IoLogoGithub className="w-4 h-auto mr-0.5" /> |
| 47 | <span className="mt-px">Star</span> |
| 48 | </span> |
| 49 | <div className="h-full block px-2 mt-px font-medium"> |
| 50 | {isRequesting ? <Icon.BiLoaderAlt className="w-3 h-auto animate-spin opacity-70" /> : stars} |
| 51 | </div> |
| 52 | </a> |
| 53 | ); |
| 54 | }; |
| 55 | |
| 56 | export default GitHubStarBadge; |
nothing calls this directly
no test coverage detected