0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-11-18 11:30:12 +09:00
yude.jp/pages/components/Minecraft/Online.js

44 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-12-11 18:55:57 +09:00
// React
import React, { useState, useEffect } from 'react';
2021-12-11 18:55:57 +09:00
// Data fetching
import axios from 'axios';
2021-12-11 18:55:57 +09:00
// i18n
import { useTranslation, useLanguageQuery } from 'next-export-i18n';
// Components
import LastPlayed from './LastPlayed'
function App (props) {
2021-12-11 18:55:57 +09:00
const { t } = useTranslation();
const [query] = useLanguageQuery();
const uuid = props;
const [data, setData] = useState({ hits: [] });
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'https://minecraft.yude.jp/online/' + uuid.uuid,
);
setData(result.data);
};
fetchData();
}, []);
if (data === undefined){
console.log("[Minecraft: オンライン状況] データの取得に失敗しました。 / Failed to retrieve data.")
return <p></p>
}else {
if (data.toString() == "false") {
return <LastPlayed uuid={uuid.uuid} />
} else {
if (data.toString() == "true") {
return <p>オンライン</p>
} else {
return <p>取得中...</p>
}
}
};
}
export default App;