mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 20:20:09 +09:00
[/minecraft/players/] Add basic function to retrieve player's data
This commit is contained in:
parent
b0b900cc10
commit
b95c6b4cd5
33
pages/components/Minecraft/LastPlayed.js
Normal file
33
pages/components/Minecraft/LastPlayed.js
Normal 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;
|
14
pages/components/Minecraft/Players.js
Normal file
14
pages/components/Minecraft/Players.js
Normal 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;
|
15
pages/components/Minecraft/UUIDCheck.js
Normal file
15
pages/components/Minecraft/UUIDCheck.js
Normal 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;
|
9
pages/components/Minecraft/WrongUUID.js
Normal file
9
pages/components/Minecraft/WrongUUID.js
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
function App (props) {
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1>入力された UUID は正しくありません。</h1>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default App;
|
26
pages/minecraft/players/[uuid].js
Normal file
26
pages/minecraft/players/[uuid].js
Normal 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>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user