Show online member discord

This commit is contained in:
Faisal Amir 2023-12-11 14:14:56 +07:00
parent a03abf0fc7
commit 730dcfcf46
2 changed files with 31 additions and 1 deletions

View File

@ -2,9 +2,11 @@ import React from "react";
import { FaGithub, FaDiscord } from "react-icons/fa";
import { RiStarSFill } from "react-icons/ri";
import { useAppStars } from "@site/src/hooks/useAppStars";
import { useDiscordWidget } from "@site/src/hooks/useDiscordWidget";
export default function SocialButton() {
const { stargazers } = useAppStars();
const { data } = useDiscordWidget();
return (
<div className="flex items-center space-x-2 justify-start">
@ -36,7 +38,7 @@ export default function SocialButton() {
<p className="text-base">Discord</p>
<div className="text-sm text-white flex items-center space-x-1">
<div className="w-2 h-2 bg-green-500 rounded-full" />
<span>{stargazers.count} online</span>
<span>{data.presence_count} online</span>
</div>
</div>
</a>

View File

@ -0,0 +1,28 @@
import React, { useEffect, useState } from "react";
import axios from "axios";
import { isAxiosError } from "axios";
export const useDiscordWidget = () => {
const [data, setData] = useState({});
useEffect(() => {
const updateData = async () => {
try {
const { data } = await axios.get(
"https://discord.com/api/guilds/1107178041848909847/widget.json"
);
setData({
...data,
});
} catch (error) {
if (isAxiosError(error)) {
console.error("Failed to get stargazers:", error);
}
}
};
updateData();
}, []);
return { data };
};