This commit is contained in:
parent
d8fe512554
commit
acebb6585c
@ -15,5 +15,5 @@ export async function GET(request: Request) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return Response.json({ error: false, data: player });
|
return Response.json({ error: false, player: player });
|
||||||
}
|
}
|
||||||
|
23
src/app/api/player/scoresaber/scores/get.ts
Normal file
23
src/app/api/player/scoresaber/scores/get.ts
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
import { fetchScores } from "@/utils/scoresaber/api";
|
||||||
|
|
||||||
|
export async function GET(request: Request) {
|
||||||
|
const { searchParams } = new URL(request.url);
|
||||||
|
const id = searchParams.get("id");
|
||||||
|
const page = searchParams.get("page");
|
||||||
|
if (!id) {
|
||||||
|
return Response.json({ error: true, message: "No player provided" });
|
||||||
|
}
|
||||||
|
if (!page) {
|
||||||
|
return Response.json({ error: true, message: "No page provided" });
|
||||||
|
}
|
||||||
|
|
||||||
|
const scores = await fetchScores(id, Number.parseInt(page), "recent", 8);
|
||||||
|
if (scores == undefined) {
|
||||||
|
return Response.json({
|
||||||
|
error: true,
|
||||||
|
message: "No players with that ID were found",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return Response.json({ error: false, scores: scores });
|
||||||
|
}
|
@ -3,32 +3,30 @@
|
|||||||
import Avatar from "@/components/Avatar";
|
import Avatar from "@/components/Avatar";
|
||||||
import Container from "@/components/Container";
|
import Container from "@/components/Container";
|
||||||
import Label from "@/components/Label";
|
import Label from "@/components/Label";
|
||||||
import { ScoresaberPlayer } from "@/schemas/scoresaber/player";
|
import { Spinner } from "@/components/Spinner";
|
||||||
|
import { ScoresaberScore } from "@/schemas/scoresaber/score";
|
||||||
import { formatNumber } from "@/utils/number";
|
import { formatNumber } from "@/utils/number";
|
||||||
import { GlobeAsiaAustraliaIcon } from "@heroicons/react/20/solid";
|
import { GlobeAsiaAustraliaIcon } from "@heroicons/react/20/solid";
|
||||||
import Image from "next/image";
|
import Image from "next/image";
|
||||||
import { useEffect, useState } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import ReactCountryFlag from "react-country-flag";
|
import ReactCountryFlag from "react-country-flag";
|
||||||
|
|
||||||
// export const metadata: Metadata = {
|
|
||||||
// title: "todo",
|
|
||||||
// };
|
|
||||||
|
|
||||||
export default function Player({ params }: { params: { id: string } }) {
|
export default function Player({ params }: { params: { id: string } }) {
|
||||||
const [error, setError] = useState(false);
|
const [error, setError] = useState(false);
|
||||||
const [errorMessage, setErrorMessage] = useState("");
|
const [errorMessage, setErrorMessage] = useState("");
|
||||||
const [loading, setLoading] = useState(true);
|
const [loadingPlayer, setLoadingPlayer] = useState(true);
|
||||||
const [playerData, setPlayerData] = useState<ScoresaberPlayer | undefined>(
|
const [playerData, setPlayerData] = useState<any>(undefined);
|
||||||
undefined,
|
|
||||||
);
|
const [loadingScores, setLoadingScores] = useState(true);
|
||||||
|
const [playerScores, setPlayerScores] = useState<ScoresaberScore[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!params.id) {
|
if (!params.id) {
|
||||||
setError(true);
|
setError(true);
|
||||||
setLoading(false);
|
setLoadingPlayer(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (error || !loading) {
|
if (error || !loadingPlayer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetch("/api/player/get?id=" + params.id).then(async (response) => {
|
fetch("/api/player/get?id=" + params.id).then(async (response) => {
|
||||||
@ -37,45 +35,38 @@ export default function Player({ params }: { params: { id: string } }) {
|
|||||||
if (json.error == true) {
|
if (json.error == true) {
|
||||||
setError(true);
|
setError(true);
|
||||||
setErrorMessage(json.message);
|
setErrorMessage(json.message);
|
||||||
setLoading(false);
|
setLoadingPlayer(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(json);
|
setPlayerData(json.player);
|
||||||
|
setLoadingPlayer(false);
|
||||||
|
|
||||||
setPlayerData(json.data);
|
fetch(`/api/player/scoresaber/scores/get?id=${params.id}&page=1`).then(
|
||||||
setLoading(false);
|
async (response) => {
|
||||||
|
const json = await response.json();
|
||||||
|
console.log(json);
|
||||||
|
|
||||||
|
if (json.error == true) {
|
||||||
|
setLoadingScores(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
setPlayerScores(json.scores);
|
||||||
|
setLoadingScores(false);
|
||||||
|
},
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}, [error, loading, params.id, playerData]);
|
}, [error, loadingPlayer, params.id]);
|
||||||
|
|
||||||
if (loading || error || !playerData) {
|
if (loadingPlayer || error || !playerData) {
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<Container>
|
<Container>
|
||||||
<div className="mt-2 flex w-full flex-col justify-center rounded-sm bg-neutral-800">
|
<div className="mt-2 flex w-full flex-col justify-center rounded-sm bg-neutral-800">
|
||||||
<div className="p-3 text-center">
|
<div className="p-3 text-center">
|
||||||
<div role="status">
|
<div role="status">
|
||||||
{loading && (
|
{loadingPlayer && <Spinner />}
|
||||||
<>
|
|
||||||
<svg
|
|
||||||
aria-hidden="true"
|
|
||||||
className="mr-2 inline h-8 w-8 animate-spin fill-blue-600 text-gray-200 dark:text-gray-600"
|
|
||||||
viewBox="0 0 100 101"
|
|
||||||
fill="none"
|
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
|
||||||
>
|
|
||||||
<path
|
|
||||||
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
|
||||||
fill="currentColor"
|
|
||||||
/>
|
|
||||||
<path
|
|
||||||
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
|
||||||
fill="currentFill"
|
|
||||||
/>
|
|
||||||
</svg>
|
|
||||||
<span className="sr-only">Loading...</span>
|
|
||||||
</>
|
|
||||||
)}
|
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<div className="flex flex-col items-center justify-center gap-2">
|
<div className="flex flex-col items-center justify-center gap-2">
|
||||||
@ -100,6 +91,7 @@ export default function Player({ params }: { params: { id: string } }) {
|
|||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<Container>
|
<Container>
|
||||||
|
{/* Player Info */}
|
||||||
<div className="mt-2 flex w-full flex-row justify-center rounded-sm bg-neutral-800 xs:flex-col">
|
<div className="mt-2 flex w-full flex-row justify-center rounded-sm bg-neutral-800 xs:flex-col">
|
||||||
<div className="flex flex-col items-center gap-3 p-3 xs:flex-row xs:items-start">
|
<div className="flex flex-col items-center gap-3 p-3 xs:flex-row xs:items-start">
|
||||||
<Avatar url={playerData.profilePicture} label="Avatar" />
|
<Avatar url={playerData.profilePicture} label="Avatar" />
|
||||||
@ -129,36 +121,49 @@ export default function Player({ params }: { params: { id: string } }) {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{/* Labels */}
|
{/* Labels */}
|
||||||
<div className="flex flex-col gap-2">
|
<div className="flex flex-wrap justify-center gap-2 xs:justify-start">
|
||||||
<div className="flex gap-2 ">
|
<Label
|
||||||
<Label
|
title="Total play count"
|
||||||
title="Total play count"
|
className="bg-blue-500"
|
||||||
className="bg-blue-500"
|
value={formatNumber(playerData.scoreStats.totalPlayCount)}
|
||||||
value={formatNumber(playerData.scoreStats.totalPlayCount)}
|
/>
|
||||||
/>
|
<Label
|
||||||
<Label
|
title="Total score"
|
||||||
title="Total score"
|
className="bg-blue-500"
|
||||||
className="bg-blue-500"
|
value={formatNumber(playerData.scoreStats.totalScore)}
|
||||||
value={formatNumber(playerData.scoreStats.totalScore)}
|
/>
|
||||||
/>
|
<Label
|
||||||
<Label
|
title="Avg ranked acc"
|
||||||
title="Avg ranked acc"
|
className="bg-blue-500"
|
||||||
className="bg-blue-500"
|
value={`${playerData.scoreStats.averageRankedAccuracy.toFixed(
|
||||||
value={`${playerData.scoreStats.averageRankedAccuracy.toFixed(
|
2,
|
||||||
2,
|
)}%`}
|
||||||
)}%`}
|
/>
|
||||||
/>
|
<Label
|
||||||
</div>
|
title="Replays watched"
|
||||||
<div className="flex gap-2">
|
value={formatNumber(playerData.scoreStats.replaysWatched)}
|
||||||
<Label
|
/>
|
||||||
title="Replays watched"
|
|
||||||
value={formatNumber(playerData.scoreStats.replaysWatched)}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* Scores */}
|
||||||
|
<div className="mt-2 flex w-full flex-row justify-center rounded-sm bg-neutral-800 xs:flex-col">
|
||||||
|
<div className="p-3">
|
||||||
|
{loadingScores ? (
|
||||||
|
<div className="flex justify-center">
|
||||||
|
<Spinner />
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
{playerScores.map((score, id) => {
|
||||||
|
return <>hi</>;
|
||||||
|
})}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
</Container>
|
</Container>
|
||||||
</main>
|
</main>
|
||||||
);
|
);
|
||||||
|
23
src/components/Spinner.tsx
Normal file
23
src/components/Spinner.tsx
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
export function Spinner() {
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<svg
|
||||||
|
aria-hidden="true"
|
||||||
|
className="mr-2 inline h-8 w-8 animate-spin fill-blue-600 text-gray-200 dark:text-gray-600"
|
||||||
|
viewBox="0 0 100 101"
|
||||||
|
fill="none"
|
||||||
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
|
>
|
||||||
|
<path
|
||||||
|
d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z"
|
||||||
|
fill="currentColor"
|
||||||
|
/>
|
||||||
|
<path
|
||||||
|
d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z"
|
||||||
|
fill="currentFill"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
<span className="sr-only">Loading...</span>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user