mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 20:20:09 +09:00
Change data retrieving method
This commit is contained in:
parent
3dd345c10f
commit
48fc60bd07
@ -7,22 +7,24 @@ function App (){
|
||||
const router = useRouter()
|
||||
const { locale, locales, defaultLocale, pathname } = router
|
||||
const { t, lang } = useTranslation("common")
|
||||
const [dataPlaying, setDataPlaying] = useState({ hits: [] });
|
||||
useEffect(async () => {
|
||||
const result = await axios(
|
||||
'https://discord.com/api/guilds/723409709306216498/widget.json',
|
||||
);
|
||||
|
||||
setDataPlaying(result.dataPlaying);
|
||||
}, []);
|
||||
if (dataPlaying === undefined){
|
||||
const [data, setData] = useState({ hits: [] });
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
const result = await axios(
|
||||
'https://discord.com/api/guilds/723409709306216498/widget.json',
|
||||
);
|
||||
setData(result.data);
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
if (data === undefined){
|
||||
console.log("[Discord API] データの取得に失敗しました。 / Failed to retrieve data.")
|
||||
return <p></p>
|
||||
}else{
|
||||
const str = JSON.stringify(dataPlaying)
|
||||
const str = JSON.stringify(data)
|
||||
|
||||
if (str.indexOf("game") !== -1){
|
||||
const yes_playing = t('yes_playing', {playing: dataPlaying.members[0].game.name})
|
||||
const yes_playing = t('yes_playing', {playing: data.members[0].game.name})
|
||||
return <p>{yes_playing}</p>
|
||||
}else{
|
||||
return <p></p>
|
||||
|
@ -8,7 +8,6 @@ export default function Minecraft(props) {
|
||||
const { locale, locales, defaultLocale, pathname } = router
|
||||
const { t, lang } = useTranslation("minecraft")
|
||||
|
||||
const [dataMinecraft, setDataMinecraft] = useState({ hits: [] });
|
||||
const [data, setData] = useState({ hits: [] });
|
||||
const fail = t('minecraft:fail')
|
||||
useEffect(() => {
|
||||
|
@ -7,21 +7,22 @@ function App () {
|
||||
const router = useRouter()
|
||||
const { locale, locales, defaultLocale, pathname } = router
|
||||
const { t, lang } = useTranslation("common")
|
||||
const [dataSpotify, setDataSpotify] = useState({ hits: [] });
|
||||
useEffect(async () => {
|
||||
const result = await axios(
|
||||
'/api/Spotify',
|
||||
);
|
||||
|
||||
setDataSpotify(result.dataSpotify);
|
||||
}, []);
|
||||
|
||||
if (dataSpotify === undefined){
|
||||
const [data, setData] = useState({ hits: [] });
|
||||
useEffect(() => {
|
||||
const fetchData = async () => {
|
||||
const result = await axios(
|
||||
'/api/Spotify',
|
||||
);
|
||||
setData(result.data);
|
||||
};
|
||||
fetchData();
|
||||
}, []);
|
||||
if (data === undefined){
|
||||
console.log("[Spotify Web API] データの取得に失敗しました。 / Failed to retrieve data.")
|
||||
return <p></p>
|
||||
}else{
|
||||
if (dataSpotify.isPlaying){
|
||||
const status = dataSpotify.artist + ' / ' + dataSpotify.title
|
||||
if (data.isPlaying){
|
||||
const status = data.artist + ' / ' + data.title
|
||||
const listening = t('listening', {listening: status})
|
||||
return <p>{listening}</p>
|
||||
}else{
|
||||
|
Loading…
Reference in New Issue
Block a user