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