0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-23 04:30:11 +09:00
yude.jp/pages/components/Discord/DiscordPlaying.js

39 lines
980 B
JavaScript
Raw Normal View History

2021-12-11 18:55:57 +09:00
// React
2021-05-28 11:43:00 +09:00
import React, { useState, useEffect } from 'react';
2021-12-11 18:55:57 +09:00
// Data fetching
2021-12-11 21:13:44 +09:00
import useSwr from 'swr'
const fetcher = (url) => fetch(url).then((res) => res.json())
2021-12-11 18:55:57 +09:00
// i18n
import { useTranslation, useLanguageQuery } from 'next-export-i18n';
2021-05-25 16:45:46 +09:00
2021-12-11 21:13:44 +09:00
export default function DiscordPlaying() {
const { t } = useTranslation();
const [query] = useLanguageQuery();
2021-12-11 21:13:44 +09:00
const { data, error } = useSwr(
`https://discord.com/api/guilds/723409709306216498/widget.json`,
fetcher
)
if (error){
console.log("[Discord API] データの取得に失敗しました。 / Failed to retrieve data.")
return <></>
} else {
if (!data) {
return <p>Loading...</p>
} else {
if (data.members) {
if (data.members[0].game) {
const yes_playing = t('yes_playing', {playing: data.members[0].game.name})
return <p>{yes_playing}</p>
} else {
return <></>
}
} else {
return <></>
}
}
2021-05-28 10:42:03 +09:00
}
}