cleanup and docs
All checks were successful
Deploy App / docker (ubuntu-latest) (push) Successful in 1m4s

This commit is contained in:
Lee
2024-04-18 07:06:16 +01:00
parent e0e6a72d92
commit 428a95c54d
18 changed files with 347 additions and 190 deletions

View File

@ -1,12 +1,18 @@
import { cn } from "@/common/utils";
import { ReactElement } from "react";
export function Card({
children,
className,
}: Readonly<{
type CardProps = {
/**
* The children for this element.
*/
children: React.ReactNode;
/**
* The class names to append.
*/
className?: string;
}>): ReactElement {
};
export function Card({ children, className }: CardProps): ReactElement {
return <div className={cn("bg-secondary rounded-lg p-3", className)}>{children}</div>;
}

View File

@ -4,9 +4,24 @@ import { atelierSeasideDark } from "react-syntax-highlighter/dist/esm/styles/hlj
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from "./ui/dialog";
type CodeDialogProps = {
/**
* The title of the dialog.
*/
title: string;
/**
* The description of the dialog.
*/
description: string;
/**
* The code to show in the dialog.
*/
code: string;
/**
* The children for this element.
*/
children: React.ReactNode;
};

View File

@ -1,11 +1,14 @@
import { ReactElement } from "react";
import NavBar from "./navbar";
export default function Container({
children,
}: Readonly<{
type ContainerProps = {
/**
* The children for this element.
*/
children: React.ReactNode;
}>): ReactElement {
};
export default function Container({ children }: ContainerProps): ReactElement {
return (
<div className="z-[9999] m-auto flex h-screen min-h-full flex-col items-center opacity-90 w-full xs:max-w-[1200px]">
<NavBar />

View File

@ -5,7 +5,14 @@ import copy from "clipboard-copy";
import { ReactElement } from "react";
type CopyButtonProps = {
/**
* The content to copy to the clipboard.
*/
content: string;
/**
* The children for this element.
*/
children: React.ReactNode;
};
@ -26,7 +33,7 @@ export function CopyButton({ content, children }: CopyButtonProps): ReactElement
title: "Copied!",
description: (
<p>
Copied <span className="font-semibold">{content}</span> to your clipboard
Copied <b>{content}</b> to your clipboard.
</p>
),
duration: 5000,

View File

@ -2,6 +2,9 @@ import { ReactElement } from "react";
import { Card } from "./card";
type ErrorProps = {
/**
* The message to show.
*/
message: string;
};

View File

@ -1,7 +1,14 @@
import Image from "next/image";
import { ReactElement } from "react";
export default function Logo({ size = 30 }: Readonly<{ size?: number }>): ReactElement {
type LogoProps = {
/**
* The size the logo will be.
*/
size?: number;
};
export default function Logo({ size = 30 }: LogoProps): ReactElement {
return (
<Image
src="https://git.fascinated.cc/MinecraftUtilities/Assets/raw/branch/master/logo.png"

View File

@ -5,16 +5,28 @@ import { RedirectButton } from "./rediect-button";
import { ToggleThemeButton } from "./theme-toggle-button";
type Page = {
title: string;
/**
* The name of the button for the navbar.
*/
name: string;
/**
* The URL to go to.
*/
url: string;
/**
* Whether clicking the button will
* open the link in a new tab.
*/
openInNewTab?: boolean;
};
const pages: Page[] = [
{ title: "Player", url: "/player" },
{ title: "Server", url: "/server/java" },
{ title: "Mojang", url: "/mojang/status" },
{ title: "API", url: "https://api.mcutils.xyz", openInNewTab: true },
{ name: "Player", url: "/player" },
{ name: "Server", url: "/server/java" },
{ name: "Mojang", url: "/mojang/status" },
{ name: "API", url: "https://api.mcutils.xyz", openInNewTab: true },
];
export default function NavBar(): ReactElement {
@ -25,15 +37,15 @@ export default function NavBar(): ReactElement {
<p className="hidden md:block">Minecraft Utilities</p>
</Link>
<div className="flex-grow"></div>
<div className="flex-grow" />
<div className="flex gap-4">
{pages.map((page, index) => {
return <RedirectButton key={index} title={page.title} url={page.url} openInNewTab={page.openInNewTab} />;
return <RedirectButton key={index} title={page.name} url={page.url} openInNewTab={page.openInNewTab} />;
})}
</div>
<div className="flex-grow"></div>
<div className="flex-grow" />
<div className="mr-4 flex items-center gap-2">
<div className="hidden md:block">

View File

@ -0,0 +1,80 @@
/* eslint-disable @next/next/no-img-element */
import { CachedPlayer, SkinPart } from "mcutils-library";
import Image from "next/image";
import Link from "next/link";
import { ReactElement } from "react";
import { Card } from "../card";
import { CodeDialog } from "../code-dialog";
import { Separator } from "../ui/separator";
import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
type PlayerViewProps = {
/**
* The player to display.
*/
player: CachedPlayer;
};
export function PlayerView({ player }: PlayerViewProps): ReactElement {
return (
<Card className="w-max xs:w-fit">
<div className="flex gap-4 flex-col xs:flex-row relative">
<div className="absolute 8xl:top-0 xs:bottom-0">
<CodeDialog
title="Player Data"
description="The player's data from the API"
code={JSON.stringify(player, undefined, 2)}
>
<button className="bg-background rounded-lg">
<p className="p-1">JSON</p>
</button>
</CodeDialog>
</div>
<div className="flex justify-center xs:justify-start">
<Image
className="w-[96px] h-[96px]"
src={player.skin.parts.head}
width={96}
height={96}
quality={100}
alt="The player's skin"
/>
</div>
<div className="flex flex-col gap-2">
<div>
<h2 className="text-xl text-primary font-semibold">{player.username}</h2>
<p>{player.uniqueId}</p>
</div>
<Separator />
<div className="flex flex-col gap-2">
<p className="text-lg">Skin Parts</p>
<div className="flex gap-2">
{Object.entries(player.skin.parts)
.filter(([part]) => part !== SkinPart.HEAD) // Don't show the head part again
.map(([part, url]) => {
return (
<Tooltip key={part}>
<TooltipTrigger>
<Link href={url} target="_blank">
<img className="h-[64px]" src={url} alt={`The player's ${part}`} loading="lazy" />
</Link>
</TooltipTrigger>
<TooltipContent>
<p>
Click to view {player.username}&apos;s {part}
</p>
</TooltipContent>
</Tooltip>
);
})}
</div>
</div>
</div>
</div>
</Card>
);
}

View File

@ -2,8 +2,20 @@ import Link from "next/link";
import { ReactElement } from "react";
type ButtonProps = {
/**
* The title of the button.
*/
title: string;
/**
* The URL to go to.
*/
url: string;
/**
* Whether clicking the button will
* open the link in a new tab.
*/
openInNewTab?: boolean;
};

View File

@ -11,6 +11,9 @@ import { Label } from "../ui/label";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "../ui/select";
type LookupServerProps = {
/**
* The current platform.
*/
currentPlatform: string;
};

View File

@ -0,0 +1,55 @@
import { formatNumber } from "@/common/number-utils";
import { CachedBedrockMinecraftServer, CachedJavaMinecraftServer } from "mcutils-library";
import Image from "next/image";
import { ReactElement } from "react";
import { Card } from "../card";
type ServerViewProps = {
/**
* The server to display.
*/
server: CachedJavaMinecraftServer | CachedBedrockMinecraftServer;
/**
* The favicon for the server.
*/
favicon: string | undefined;
};
export function ServerView({ server, favicon }: ServerViewProps): ReactElement {
return (
<Card className="w-max xs:w-fit relative">
<div className="flex gap-2 flex-col">
<div className="flex gap-4 flex-col xs:flex-row">
{favicon && (
<div className="flex justify-center xs:justify-start">
<Image
className="w-[64px] h-[64px]"
src={favicon}
width={64}
height={64}
quality={100}
alt="The server's favicon"
/>
</div>
)}
<div className="flex flex-col">
<h2 className="text-xl text-primary font-semibold">{server.hostname}</h2>
<div>
<p>
Players online: {formatNumber(server.players.online)}/{formatNumber(server.players.max)}
</p>
</div>
</div>
</div>
<div className="bg-background rounded-lg p-2 text-sm xs:text-lg">
{server.motd.html.map((line, index) => {
return <p key={index} dangerouslySetInnerHTML={{ __html: line }}></p>;
})}
</div>
</div>
</Card>
);
}

View File

@ -2,8 +2,19 @@ import { ReactElement } from "react";
import CountUp from "react-countup";
type StatProps = {
/**
* The title of this statistic.
*/
title: string;
/**
* The value to display for this statistic.
*/
value: number;
/**
* The icon to display.
*/
icon: ReactElement;
};

View File

@ -7,9 +7,24 @@ import useWebSocket, { ReadyState } from "react-use-websocket";
import { Tooltip, TooltipContent, TooltipTrigger } from "./ui/tooltip";
type Stat = {
/**
* The metric ID from the websocket.
*/
id: string;
/**
* The display name for this statistic.
*/
displayName: string;
/**
* The tooltip to display for this statistic.
*/
tooltip: string;
/**
* The icon to use for this statistic.
*/
icon: ReactElement;
};