add server page and update player page
Some checks failed
Deploy App / docker (ubuntu-latest) (push) Failing after 47s

This commit is contained in:
Lee
2024-04-14 21:56:07 +01:00
parent 094a6c697e
commit 2597c51863
9 changed files with 118 additions and 34 deletions

View File

@ -4,7 +4,7 @@ export default function Player() {
return (
<div className="h-full flex flex-col items-center">
<div className="mb-4 text-center">
<h1 className="text-xl">Search for a Player</h1>
<h1 className="text-xl">Lookup a Player</h1>
<p>You can enter a players uuid or username to get information about the player.</p>
</div>
<PlayerSearch />

13
src/app/server/page.tsx Normal file
View File

@ -0,0 +1,13 @@
import ServerSearch from "@/components/server-search";
export default function Player() {
return (
<div className="h-full flex flex-col items-center">
<div className="mb-4 text-center">
<h1 className="text-xl">Lookup a Server</h1>
<p>You can enter a server ip or domain to get information about the server.</p>
</div>
<ServerSearch />
</div>
);
}

View File

@ -9,6 +9,7 @@ type Page = {
const pages: Page[] = [
{ title: "Home", url: "/" },
{ title: "Player", url: "/player" },
{ title: "Server", url: "/server" },
];
export default function NavBar() {

View File

@ -12,7 +12,7 @@ export default function PlayerSearch() {
const [playerId, setPlayerId] = useState<string | null>(null);
const [player, setPlayer] = useState<any | null>(null);
const handleSearch = () => {
const handleLookup = () => {
if (playerId === null || playerId.length <= 0) {
toast.error("Please enter a player ID");
return;
@ -29,7 +29,7 @@ export default function PlayerSearch() {
const handleKeyDown = (e: any) => {
if (e.key === "Enter") {
handleSearch();
handleLookup();
}
};
@ -42,33 +42,31 @@ export default function PlayerSearch() {
onChange={(e) => setPlayerId(e.target.value)}
onKeyDown={handleKeyDown}
/>
<Button onClick={() => handleSearch()}>Search</Button>
<Button onClick={() => handleLookup()}>Lookup</Button>
</div>
{player && (
<div className="bg-secondary rounded-lg p-2 min-w-[600px] max-w-full">
<div className="flex gap-4 p-2">
<Image src={player.skin.parts.head} alt="The player's Head" width={150} height={150} />
<div className="flex flex-col gap-1 mt-2">
<p>
Unique ID: <span className="font-bold">{player.uniqueId}</span>
</p>
<p>
Name: <span className="font-bold">{player.username}</span>
</p>
<div className="mt-2">
<p>Skin Parts</p>
<div className="flex gap-2">
{Object.keys(player.skin.parts).map((part: any, index: number) => {
return (
<p key={index}>
<Link className="text-primary" href={player.skin.parts[part]} target="_blank">
{part}
</Link>
</p>
);
})}
</div>
<div className="bg-secondary rounded-lg p-4 min-w-[600px] max-w-full flex flex-row gap-2">
<Image src={player.skin.parts.head} alt="The player's Head" width={150} height={150} />
<div className="flex flex-col gap-1 mt-2">
<p>
Unique ID: <span className="font-bold">{player.uniqueId}</span>
</p>
<p>
Name: <span className="font-bold">{player.username}</span>
</p>
<div className="mt-2">
<p>Skin Parts</p>
<div className="flex gap-2">
{Object.keys(player.skin.parts).map((part: any, index: number) => {
return (
<p key={index}>
<Link className="text-primary" href={player.skin.parts[part]} target="_blank">
{part}
</Link>
</p>
);
})}
</div>
</div>
</div>

View File

@ -0,0 +1,74 @@
"use client";
import { cn } from "@/common/utils";
import mcUtils from "mcutils-library";
import JavaMinecraftServer from "mcutils-library/dist/types/server/javaServer";
import { ServerPlatform } from "mcutils-library/dist/types/server/platform";
import Image from "next/image";
import { useState } from "react";
import { toast } from "react-toastify";
import { Button } from "./ui/button";
import { Input } from "./ui/input";
export default function ServerSearch() {
const [serverHostname, setServerHostname] = useState<string | null>(null);
const [server, setServer] = useState<JavaMinecraftServer | null>(null);
const handleLookup = () => {
if (serverHostname === null || serverHostname.length <= 0) {
toast.error("Please enter a server hostname");
return;
}
mcUtils.server
.getServer(ServerPlatform.Java, serverHostname)
.then((response) => {
setServer(response.server as JavaMinecraftServer);
})
.catch(() => {
toast.error("Server not found");
});
};
const handleKeyDown = (e: any) => {
if (e.key === "Enter") {
handleLookup();
}
};
return (
<div className="flex flex-col items-center gap-8">
<div className="flex items-center gap-2">
<Input
className="w-[200px]"
placeholder="Server Domain or IP"
onChange={(e) => setServerHostname(e.target.value)}
onKeyDown={handleKeyDown}
/>
<Button onClick={() => handleLookup()}>Lookup</Button>
</div>
{server && (
<div className="bg-secondary rounded-lg p-4 min-w-[460px] max-w-full flex flex-col gap-2">
<div className="flex flex-row gap-3 items-center">
<Image src={server.favicon.url} alt="The server's Icon" width={64} height={64} />
<div className={cn("flex flex-col gap-2")}>
{server.motd.html.map((line, index) => {
return <div key={index} dangerouslySetInnerHTML={{ __html: line }} />;
})}
</div>
</div>
<div className="flex flex-col gap-1">
<div>
<span className="font-bold">Host:</span> {server.hostname}
</div>
<div>
<span className="font-bold">Players:</span> {server.players.online}/{server.players.max}
</div>
</div>
</div>
)}
</div>
);
}