0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-12-22 12:10:11 +09:00

[/minecraft/players/] Add basic function to retrieve player's data

This commit is contained in:
yude 2021-09-24 09:15:03 +09:00
parent b0b900cc10
commit b95c6b4cd5
Signed by: yude
GPG Key ID: EB0FE5D925C4A968
5 changed files with 97 additions and 0 deletions

View File

@ -0,0 +1,33 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
import useTranslation from 'next-translate/useTranslation'
import { useRouter } from 'next/router'
function App (props) {
const uuid = props;
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("common")
const [data, setData] = useState({ hits: [] });
useEffect(() => {
const fetchData = async () => {
const result = await axios(
'https://minecraft.yude.jp/last/' + uuid.uuid,
);
setData(result.data);
};
fetchData();
}, []);
if (data === undefined){
console.log("[Minecraft: 最終プレイ日時] データの取得に失敗しました。 / Failed to retrieve data.")
return <p></p>
}else {
if (data.toString() == "[object Object]") {
return <p>取得中です...</p>
} else {
return <p>{data.toString()}</p>
}
};
}
export default App;

View File

@ -0,0 +1,14 @@
import LastPlayed from './LastPlayed'
function App (props) {
const uuid = props;
return (
<div>
<p>UUID: {uuid.uuid}</p>
<p>Last played: <LastPlayed uuid={uuid.uuid} /></p>
</div>
)
}
export default App;

View File

@ -0,0 +1,15 @@
import Players from './Players'
import WrongUUID from './WrongUUID'
function App (props) {
const uuid = props;
const regex = "[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}";
if (uuid.uuid.match(regex)) {
return <Players uuid={uuid.uuid} />
} else {
return <WrongUUID />
}
}
export default App;

View File

@ -0,0 +1,9 @@
function App (props) {
return (
<div>
<h1>入力された UUID は正しくありません</h1>
</div>
)
}
export default App;

View File

@ -0,0 +1,26 @@
// Base layout
import Layout from "../../components/Layout"
// i18n
import useTranslation from 'next-translate/useTranslation'
// React
import { useRouter } from 'next/router'
// Data fetching
import UUIDCheck from '../../components/Minecraft/UUIDCheck'
export default function Players() {
const router = useRouter()
const { locale, locales, defaultLocale, pathname } = router
const { t, lang } = useTranslation("index")
const { uuid } = router.query
return (
<>
<Layout title={t('home')}>
<UUIDCheck uuid={uuid} />
</Layout>
</>
)
}