0
0
mirror of https://github.com/yude-jp/yude.jp synced 2025-10-13 11:48:37 +09:00

Fix 404 page @ minecraft/players/[uuid]

This commit is contained in:
2021-09-26 13:36:23 +09:00
parent 5276456ac2
commit ea617dd8dc
4 changed files with 48 additions and 37 deletions

View File

@@ -1,40 +1,39 @@
import React, { useState, useEffect } from 'react';
import axios from 'axios';
// Component
import Group from './Group';
// Data fetching
import useSwr from 'swr'
const fetcher = (url) => fetch(url).then((res) => res.json())
function App (props) {
const uuid = props;
const [data, setData] = useState({ hits: [] });
useEffect(() => {
const fetchData = async () => {
let result = null;
try {
result = await axios('https://api.ashcon.app/mojang/v2/user/' + uuid.uuid);
setData(result.data);
} catch (err) {
result = 404;
setData(result);
}
};
fetchData();
}, []);
if (data === undefined){
console.log("[Minecraft: UUID to player's name] データの取得に失敗しました。 / Failed to retrieve data.")
return <>取得中...</>
}else {
if (data === 404) {
return <p>そのようなプレイヤーは存在しません</p>
} else {
const { data, error } = useSwr(
uuid.uuid ? `/api/PlayerName/${uuid.uuid}` : null,
fetcher
)
if (error) {
return (
<>エラーが発生しました</>
)
} else {
if (!data) {
return (
<>読み込み中...</>
)
} else {
return (
<div className='has-tooltip'>
<span className='tooltip rounded shadow-lg p-1 bg-gray-100 text-red-500 -mt-8 font-mono text-sm'>UUID: {uuid.uuid}</span>
<p className="text-2xl inline">{data.username}</p>
<Group uuid={uuid.uuid} />
</div>
<>
<div className='has-tooltip'>
<span className='tooltip rounded shadow-lg p-1 bg-gray-100 text-red-500 -mt-8 font-mono text-sm'>UUID: {uuid.uuid}</span>
<p className="text-2xl inline">{data.username}</p>
<Group uuid={uuid.uuid} />
</div>
</>
)
}
};
}
}
}
export default App;

View File

@@ -1,3 +1,4 @@
// Components
import Online from './Online'
import Head from './Head'
import PlayerNameHolder from './PlayerNameHolder'

View File

@@ -1,7 +1,7 @@
function App (props) {
return (
<div>
<h1>入力された UUID は正しくありません</h1>
<div className="text-center">
<h2>入力された UUID に該当するプレイヤーが見つかりませんでした</h2>
</div>
)
}