mirror of
https://github.com/yude-jp/yude.jp
synced 2025-01-03 10:00:11 +09:00
Change data fetching / rendering method
This commit is contained in:
parent
48fc60bd07
commit
8406afaa29
@ -1,27 +1,36 @@
|
|||||||
import React from "react";
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import axios from 'axios';
|
||||||
|
|
||||||
const url = "https://discord.com/api/guilds/723409709306216498/widget.json";
|
const url = "https://discord.com/api/guilds/723409709306216498/widget.json";
|
||||||
const App = () => {
|
const App = () => {
|
||||||
const [status, setStatus] = React.useState(0);
|
const [data, setData] = useState({ hits: [] });
|
||||||
React.useEffect(() => {
|
useEffect(() => {
|
||||||
fetch(url)
|
const fetchData = async () => {
|
||||||
.then((r) => r.json())
|
const result = await axios(
|
||||||
.then((j) => setStatus(j.members[0].status))
|
'https://discord.com/api/guilds/723409709306216498/widget.json',
|
||||||
|
);
|
||||||
|
setData(result.data);
|
||||||
|
};
|
||||||
|
fetchData();
|
||||||
}, []);
|
}, []);
|
||||||
|
const status = data.members && data.members[0].status;
|
||||||
if (status === "online") {
|
return (
|
||||||
return <div className="font-bold text-gray-700 rounded-full bg-green-500 flex w-5 h-5 items-center justify-center"></div>
|
<>
|
||||||
}else{
|
{
|
||||||
if (status === "idle") {
|
(() => {
|
||||||
return <div className="font-bold text-gray-700 rounded-full bg-yellow-500 flex w-5 h-5 items-center justify-center"></div>
|
if (status == "online"){
|
||||||
}else{
|
return <div className="z-1000 text-green-700 rounded-full bg-green-500 flex w-5 h-5"></div>
|
||||||
if (status === "dnd") {
|
} else if (status == "idle"){
|
||||||
return <div className="font-bold text-gray-700 rounded-full bg-red-500 flex w-5 h-5 items-center justify-center"></div>
|
return <div className="z-1000 text-yellow-700 rounded-full bg-green-500 flex w-5 h-5"></div>
|
||||||
}else{
|
} else if (status == "dnd"){
|
||||||
return <div className="font-bold text-gray-700 rounded-full bg-gray-500 flex w-5 h-5 items-center justify-center"></div>
|
return <div className="z-1000 text-yellow-700 rounded-full bg-red-500 flex w-5 h-5"></div>
|
||||||
|
} else {
|
||||||
|
return <div className="z-1000 text-gray-700 rounded-full bg-red-500 flex w-5 h-5"></div>
|
||||||
}
|
}
|
||||||
|
})()
|
||||||
}
|
}
|
||||||
}
|
</>
|
||||||
};
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
Loading…
Reference in New Issue
Block a user