From 7629eb6c49375ea9eed85c258734280dcc119d92 Mon Sep 17 00:00:00 2001 From: yudejp Date: Fri, 24 Sep 2021 16:47:45 +0900 Subject: [PATCH] Implement basic user page for Minecraft server --- pages/components/Minecraft/GetName.js | 28 +++++++++++++++++ pages/components/Minecraft/Head.js | 16 ++++++++++ pages/components/Minecraft/LastPlayed.js | 35 ++++++++++++++++++++- pages/components/Minecraft/Online.js | 39 ++++++++++++++++++++++++ pages/components/Minecraft/Players.js | 18 ++++++++--- 5 files changed, 131 insertions(+), 5 deletions(-) create mode 100644 pages/components/Minecraft/GetName.js create mode 100644 pages/components/Minecraft/Head.js create mode 100644 pages/components/Minecraft/Online.js diff --git a/pages/components/Minecraft/GetName.js b/pages/components/Minecraft/GetName.js new file mode 100644 index 0000000..0cbeb82 --- /dev/null +++ b/pages/components/Minecraft/GetName.js @@ -0,0 +1,28 @@ +import React, { useState, useEffect } from 'react'; +import axios from 'axios'; + +function App (props) { + const uuid = props; + const [data, setData] = useState({ hits: [] }); +// const uuid_nohyphen = uuid.uuid.toString().replace(/-/g, ""); + + useEffect(() => { + const fetchData = async () => { + const result = await axios( + 'https://api.ashcon.app/mojang/v2/user/' + uuid.uuid, + ); + setData(result.data); + }; + fetchData(); + }, []); + if (data === undefined){ + console.log("[Minecraft: UUID to player's name] データの取得に失敗しました。 / Failed to retrieve data.") + return + }else { + return {data.username} + }; + + // return
{uuid_nohyphen}
+} + +export default App; \ No newline at end of file diff --git a/pages/components/Minecraft/Head.js b/pages/components/Minecraft/Head.js new file mode 100644 index 0000000..300d708 --- /dev/null +++ b/pages/components/Minecraft/Head.js @@ -0,0 +1,16 @@ +import React, { useState, useEffect } from 'react'; +import Image from 'next/image' + +function App (props) { + const uuid = props; + + return ( +取得中です...
} else { - return{data.toString()}
+ let dateTime = new Date(parseInt(data.toString()) * 1000); + return ( +オンライン
+ } else { + return取得中...
+ } + } + }; +} + +export default App; \ No newline at end of file diff --git a/pages/components/Minecraft/Players.js b/pages/components/Minecraft/Players.js index a466c4d..2ae24bd 100644 --- a/pages/components/Minecraft/Players.js +++ b/pages/components/Minecraft/Players.js @@ -1,12 +1,22 @@ -import LastPlayed from './LastPlayed' +import Online from './Online' +import Head from './Head' +import GetName from './GetName' function App (props) { const uuid = props; return ( -UUID: {uuid.uuid}
-Last played:
UUID: {uuid.uuid}
+