From c286ae4a210cac0d13bc04a739c32229d71ceaf3 Mon Sep 17 00:00:00 2001 From: Rainnny7 Date: Sat, 20 Apr 2024 14:18:52 -0400 Subject: [PATCH] Cleanup player page --- .../app/(pages)/player/[[...slug]]/page.tsx | 31 +++++-------------- 1 file changed, 8 insertions(+), 23 deletions(-) diff --git a/Frontend/src/app/(pages)/player/[[...slug]]/page.tsx b/Frontend/src/app/(pages)/player/[[...slug]]/page.tsx index 8a76995..4c76079 100644 --- a/Frontend/src/app/(pages)/player/[[...slug]]/page.tsx +++ b/Frontend/src/app/(pages)/player/[[...slug]]/page.tsx @@ -71,10 +71,15 @@ export const generateMetadata = async ({ params, }: PageProps): Promise => { const query: string | undefined = trimQuery(params.slug?.[0]); - let embed: Metadata | undefined; + let embed: Metadata | undefined; // The player embed, if any if (query) { try { - embed = await getPlayerEmbed(query); // Get the player embed + const player: CachedPlayer = await getPlayer(query); // Get the player to embed + return Embed({ + title: `${player.username}'s Profile`, + description: `UUID: ${player.uniqueId}\n\nClick to view data about this player.`, + thumbnail: player.skin.parts.HEAD, + }); } catch (err) { const code: number = (err as RestfulMCAPIError).code; // Get the error status code if (code === 400) { @@ -112,7 +117,7 @@ export const generateViewport = async ({ const query: string | undefined = trimQuery(params.slug?.[0]); if (query) { try { - await getPlayerEmbed(query); // Try and get the player embed + await getPlayer(query); // Try and get the player embed return { themeColor: "#55FF55" }; // Online } catch (err) { return { themeColor: "#AA0000" }; // Error @@ -135,24 +140,4 @@ const trimQuery = (query: string | undefined): string | undefined => { return query; }; -/** - * Get the embed for this page. - * - * @param query the query to embed, if any - * @returns the page embed - */ -const getPlayerEmbed = async ( - query: string | undefined -): Promise => { - if (!query) { - return undefined; - } - const player: CachedPlayer = await getPlayer(query); // Get the player to embed - return Embed({ - title: `${player.username}'s Profile`, - description: `UUID: ${player.uniqueId}\n\nClick to view data about this player.`, - thumbnail: player.skin.parts.HEAD, - }); -}; - export default PlayerPage;