mirror of
https://github.com/yude-jp/yude.jp
synced 2024-12-22 20:20:09 +09:00
Fix 404 page @ minecraft/players/[uuid]
This commit is contained in:
parent
5276456ac2
commit
ea617dd8dc
@ -1,40 +1,39 @@
|
|||||||
import React, { useState, useEffect } from 'react';
|
// Component
|
||||||
import axios from 'axios';
|
|
||||||
import Group from './Group';
|
import Group from './Group';
|
||||||
|
|
||||||
|
// Data fetching
|
||||||
|
import useSwr from 'swr'
|
||||||
|
|
||||||
|
const fetcher = (url) => fetch(url).then((res) => res.json())
|
||||||
|
|
||||||
function App (props) {
|
function App (props) {
|
||||||
const uuid = props;
|
const uuid = props;
|
||||||
const [data, setData] = useState({ hits: [] });
|
const { data, error } = useSwr(
|
||||||
|
uuid.uuid ? `/api/PlayerName/${uuid.uuid}` : null,
|
||||||
|
fetcher
|
||||||
|
)
|
||||||
|
|
||||||
useEffect(() => {
|
if (error) {
|
||||||
const fetchData = async () => {
|
return (
|
||||||
let result = null;
|
<>エラーが発生しました。</>
|
||||||
try {
|
)
|
||||||
result = await axios('https://api.ashcon.app/mojang/v2/user/' + uuid.uuid);
|
} else {
|
||||||
setData(result.data);
|
if (!data) {
|
||||||
} catch (err) {
|
return (
|
||||||
result = 404;
|
<>読み込み中...</>
|
||||||
setData(result);
|
)
|
||||||
}
|
} else {
|
||||||
};
|
|
||||||
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 {
|
|
||||||
return (
|
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>
|
<div className='has-tooltip'>
|
||||||
<p className="text-2xl inline">{data.username}</p>
|
<span className='tooltip rounded shadow-lg p-1 bg-gray-100 text-red-500 -mt-8 font-mono text-sm'>UUID: {uuid.uuid}</span>
|
||||||
<Group uuid={uuid.uuid} />
|
<p className="text-2xl inline">{data.username}</p>
|
||||||
</div>
|
<Group uuid={uuid.uuid} />
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default App;
|
export default App;
|
@ -1,3 +1,4 @@
|
|||||||
|
// Components
|
||||||
import Online from './Online'
|
import Online from './Online'
|
||||||
import Head from './Head'
|
import Head from './Head'
|
||||||
import PlayerNameHolder from './PlayerNameHolder'
|
import PlayerNameHolder from './PlayerNameHolder'
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
function App (props) {
|
function App (props) {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className="text-center">
|
||||||
<h1>入力された UUID は正しくありません。</h1>
|
<h2>入力された UUID に該当するプレイヤーが見つかりませんでした。</h2>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,12 @@ import { useRouter } from 'next/router'
|
|||||||
|
|
||||||
// Data fetching
|
// Data fetching
|
||||||
import Players from '../../components/Minecraft/Players'
|
import Players from '../../components/Minecraft/Players'
|
||||||
import PlayerName from '../../components/Minecraft/PlayerName'
|
|
||||||
import useSwr from 'swr'
|
import useSwr from 'swr'
|
||||||
|
|
||||||
const fetcher = (url) => fetch(url).then((res) => res.json())
|
const fetcher = (url) => fetch(url).then((res) => res.json())
|
||||||
|
|
||||||
|
// Components
|
||||||
|
import WrongUUID from '../../components/Minecraft/WrongUUID'
|
||||||
|
|
||||||
export default function UUID() {
|
export default function UUID() {
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const { uuid } = router.query
|
const { uuid } = router.query
|
||||||
@ -36,13 +37,23 @@ export default function UUID() {
|
|||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
|
if (!data.username) {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Layout title={data.username + " - " + "プレイヤー情報"}>
|
<Layout title="404 - プレイヤー情報">
|
||||||
<Players uuid={uuid} />
|
<WrongUUID />
|
||||||
</Layout>
|
</Layout>
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<Layout title={data.username + " - " + "プレイヤー情報"}>
|
||||||
|
<Players uuid={uuid} />
|
||||||
|
</Layout>
|
||||||
|
</>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user