2021-12-11 18:55:57 +09:00
|
|
|
// React
|
2021-09-24 16:47:45 +09:00
|
|
|
import React, { useState, useEffect } from 'react';
|
2021-12-11 18:55:57 +09:00
|
|
|
|
|
|
|
// Data fetching
|
2021-09-24 16:47:45 +09:00
|
|
|
import axios from 'axios';
|
2021-12-11 18:55:57 +09:00
|
|
|
|
|
|
|
// i18n
|
|
|
|
import { useTranslation, useLanguageQuery } from 'next-export-i18n';
|
|
|
|
|
|
|
|
// Components
|
2021-09-24 16:47:45 +09:00
|
|
|
import LastPlayed from './LastPlayed'
|
|
|
|
|
|
|
|
function App (props) {
|
2021-12-11 18:55:57 +09:00
|
|
|
const { t } = useTranslation();
|
|
|
|
const [query] = useLanguageQuery();
|
2021-09-24 16:47:45 +09:00
|
|
|
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;
|