Show online member discord
This commit is contained in:
parent
a03abf0fc7
commit
730dcfcf46
@ -2,9 +2,11 @@ import React from "react";
|
|||||||
import { FaGithub, FaDiscord } from "react-icons/fa";
|
import { FaGithub, FaDiscord } from "react-icons/fa";
|
||||||
import { RiStarSFill } from "react-icons/ri";
|
import { RiStarSFill } from "react-icons/ri";
|
||||||
import { useAppStars } from "@site/src/hooks/useAppStars";
|
import { useAppStars } from "@site/src/hooks/useAppStars";
|
||||||
|
import { useDiscordWidget } from "@site/src/hooks/useDiscordWidget";
|
||||||
|
|
||||||
export default function SocialButton() {
|
export default function SocialButton() {
|
||||||
const { stargazers } = useAppStars();
|
const { stargazers } = useAppStars();
|
||||||
|
const { data } = useDiscordWidget();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex items-center space-x-2 justify-start">
|
<div className="flex items-center space-x-2 justify-start">
|
||||||
@ -36,7 +38,7 @@ export default function SocialButton() {
|
|||||||
<p className="text-base">Discord</p>
|
<p className="text-base">Discord</p>
|
||||||
<div className="text-sm text-white flex items-center space-x-1">
|
<div className="text-sm text-white flex items-center space-x-1">
|
||||||
<div className="w-2 h-2 bg-green-500 rounded-full" />
|
<div className="w-2 h-2 bg-green-500 rounded-full" />
|
||||||
<span>{stargazers.count} online</span>
|
<span>{data.presence_count} online</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</a>
|
</a>
|
||||||
|
|||||||
28
docs/src/hooks/useDiscordWidget.js
Normal file
28
docs/src/hooks/useDiscordWidget.js
Normal 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 };
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user