0
0
mirror of https://github.com/yude-jp/yude.jp synced 2024-11-01 16:07:59 +09:00
yude.jp/pages/minecraft/players/[uuid].js

49 lines
1.1 KiB
JavaScript
Raw Normal View History

2021-09-26 13:24:10 +09:00
// Base layout
import Layout from "../../components/Layout"
// React
import { useRouter } from 'next/router'
// Data fetching
import Players from '../../components/Minecraft/Players'
import PlayerName from '../../components/Minecraft/PlayerName'
2021-09-26 12:52:37 +09:00
import useSwr from 'swr'
const fetcher = (url) => fetch(url).then((res) => res.json())
export default function UUID() {
const router = useRouter()
const { uuid } = router.query
2021-09-26 12:52:37 +09:00
const { data, error } = useSwr(
2021-09-26 13:24:10 +09:00
uuid ? `/api/PlayerName/${uuid}` : null,
2021-09-26 12:52:37 +09:00
fetcher
)
if (error) {
return (
<>
<Layout title="エラー - プレイヤー情報">
<p className="text-2xl">エラーが発生しました</p>
</Layout>
</>
)
2021-09-26 13:24:10 +09:00
} else {
if (!data) {
return (
<>
<Layout title="読み込み中... - プレイヤー情報">
<Players uuid={uuid} />
</Layout>
</>
)
} else {
return (
<>
<Layout title={data.username + " - " + "プレイヤー情報"}>
<Players uuid={uuid} />
</Layout>
</>
)
}
2021-09-26 12:52:37 +09:00
}
}