Embed color test
Some checks failed
Deploy Frontend / docker (17, 3.8.5) (push) Failing after 29s

This commit is contained in:
Braydon 2024-04-19 11:33:29 -04:00
parent 4af63c65a0
commit d46fd443d4
2 changed files with 61 additions and 41 deletions

@ -6,7 +6,7 @@ import { minecrafter } from "@/font/fonts";
import { cn } from "@/lib/utils"; import { cn } from "@/lib/utils";
import { PageProps } from "@/types/page"; import { PageProps } from "@/types/page";
import { ExclamationCircleIcon } from "@heroicons/react/24/outline"; import { ExclamationCircleIcon } from "@heroicons/react/24/outline";
import { Metadata } from "next"; import { Metadata, Viewport } from "next";
import { ReactElement } from "react"; import { ReactElement } from "react";
import { CachedPlayer, getPlayer, type RestfulMCAPIError } from "restfulmc-lib"; import { CachedPlayer, getPlayer, type RestfulMCAPIError } from "restfulmc-lib";
@ -65,44 +65,37 @@ const PlayerPage = async ({ params }: PageProps): Promise<ReactElement> => {
* Generate metadata for this page. * Generate metadata for this page.
* *
* @param params the route params * @param params the route params
* @param searchParams the search params
* @returns the generated metadata * @returns the generated metadata
*/ */
export const generateMetadata = async ({ export const generateMetadata = async ({
params, params,
}: PageProps): Promise<Metadata> => { }: PageProps): Promise<Metadata> => {
const query: string | undefined = trimQuery(params.slug?.[0]); // The query to embed for const embed: Metadata | undefined = await getPageEmbed(
trimQuery(params.slug?.[0])
); // Get the page embed
// Try and get the player to display // Return the page embed
if (query) { return embed
try { ? embed
const player: CachedPlayer = await getPlayer(query); // Get the player to embed : Embed({
return Embed({ title: "Player Lookup",
title: `${player.username}'s Profile`, description: "Search for a player to view their 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 * Generate the viewport for this page.
if (code === 400) { *
return Embed({ * @param params the route params
title: "Invalid Player", * @returns the generated metadata
color: "#EB4034", */
description: `The player ${query} is invalid.`, export const generateViewport = async ({
}); params,
} else if (code === 404) { }: PageProps): Promise<Viewport> => {
return Embed({ const embed: Metadata | undefined = await getPageEmbed(
title: "Player Not Found", trimQuery(params.slug?.[0])
color: "#EB4034", ); // Get the page embed
description: `The player ${query} was not found.`, return embed ? {} : { themeColor: "#FF5555" };
});
}
}
}
return Embed({
title: "Player Lookup",
description: "Search for a player to view their profile.",
});
}; };
/** /**
@ -119,4 +112,39 @@ const trimQuery = (query: string | undefined): string | undefined => {
return query; return query;
}; };
/**
* Get the embed for this page.
*
* @param query the query to embed, if any
* @returns the page embed
*/
const getPageEmbed = async (
query: string | undefined
): Promise<Metadata | undefined> => {
if (!query) {
return undefined;
}
try {
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) {
return Embed({
title: "Invalid Player",
description: `The player ${query} is invalid.`,
});
} else if (code === 404) {
return Embed({
title: "Player Not Found",
description: `The player ${query} was not found.`,
});
}
}
};
export default PlayerPage; export default PlayerPage;

@ -9,13 +9,6 @@ type EmbedProps = {
*/ */
title: string; title: string;
/**
* The color of this embed, undefined
* for no custom color.
* // TODO: make this work lol
*/
color?: string | undefined;
/** /**
* The description of the embed. * The description of the embed.
*/ */
@ -35,7 +28,6 @@ type EmbedProps = {
*/ */
const Embed = ({ const Embed = ({
title, title,
color,
description, description,
thumbnail = "", thumbnail = "",
}: EmbedProps): Metadata => { }: EmbedProps): Metadata => {