2024-04-16 17:54:22 +01:00
|
|
|
"use client";
|
|
|
|
|
2024-04-17 17:21:15 +01:00
|
|
|
import { ServerPlatform } from "mcutils-library";
|
2024-04-16 17:54:22 +01:00
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
import { useState } from "react";
|
2024-04-16 19:12:26 +01:00
|
|
|
import { Button } from "../ui/button";
|
|
|
|
import { Input } from "../ui/input";
|
2024-04-16 17:54:22 +01:00
|
|
|
|
2024-04-16 21:18:08 +01:00
|
|
|
export function LookupServer(): JSX.Element {
|
2024-04-16 17:54:22 +01:00
|
|
|
const router = useRouter();
|
|
|
|
const [hostname, setHostname] = useState("");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the hostname value
|
|
|
|
*
|
|
|
|
* @param event the input event
|
|
|
|
*/
|
|
|
|
const setHostnameValue = (event: React.ChangeEvent<HTMLInputElement>) => {
|
|
|
|
setHostname(event.target.value);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Lookup a server based on the platform
|
|
|
|
*
|
|
|
|
* @param platform the server platform
|
|
|
|
*/
|
|
|
|
const lookupServer = (platform: ServerPlatform) => {
|
2024-04-16 18:49:23 +01:00
|
|
|
if (!hostname || hostname.length === 0) {
|
|
|
|
return;
|
|
|
|
}
|
2024-04-16 17:54:22 +01:00
|
|
|
router.push(`/server/${platform}/${hostname}`);
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
2024-04-16 21:50:08 +01:00
|
|
|
<form className="flex gap-2 justify-center items-center mt-2 flex-col xs:flex-row">
|
|
|
|
<Input className="w-fit" placeholder="Hostname" value={hostname} onChange={setHostnameValue} maxLength={128} />
|
|
|
|
<div className="flex gap-2 justify-center">
|
|
|
|
<Button onClick={() => lookupServer(ServerPlatform.Java)}>Java</Button>
|
|
|
|
<Button onClick={() => lookupServer(ServerPlatform.Bedrock)}>Bedrock</Button>
|
|
|
|
</div>
|
2024-04-16 19:35:07 +01:00
|
|
|
</form>
|
2024-04-16 17:54:22 +01:00
|
|
|
);
|
|
|
|
}
|