From cb91880cafb8523a332a39457332c0a5b3b1d54c Mon Sep 17 00:00:00 2001 From: Liam Date: Mon, 15 Apr 2024 09:03:06 +0100 Subject: [PATCH] use updated library --- package.json | 2 +- pnpm-lock.yaml | 8 ++++---- src/components/player-search.tsx | 21 +++++++++++---------- src/components/server-search.tsx | 20 ++++++++++---------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/package.json b/package.json index 1f8bb00..d602e59 100644 --- a/package.json +++ b/package.json @@ -14,7 +14,7 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "lucide-react": "^0.368.0", - "mcutils-library": "^1.0.2", + "mcutils-library": "^1.1.0", "next": "14.2.1", "next-themes": "^0.3.0", "react": "^18", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6791213..6ddf07b 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -21,8 +21,8 @@ dependencies: specifier: ^0.368.0 version: 0.368.0(react@18.2.0) mcutils-library: - specifier: ^1.0.2 - version: 1.0.2(@babel/core@7.24.4)(@types/node@20.12.7) + specifier: ^1.1.0 + version: 1.1.0(@babel/core@7.24.4)(@types/node@20.12.7) next: specifier: 14.2.1 version: 14.2.1(@babel/core@7.24.4)(react-dom@18.2.0)(react@18.2.0) @@ -3516,8 +3516,8 @@ packages: tmpl: 1.0.5 dev: false - /mcutils-library@1.0.2(@babel/core@7.24.4)(@types/node@20.12.7): - resolution: {integrity: sha512-Yl9w3H4FqDmhki32HGvR1jDLzhSJqaWuBiUqYom+5IZk6sLh5j6yfRVFvwHTOLfx/Ee43FWFBXeM+9TQoTUC4Q==} + /mcutils-library@1.1.0(@babel/core@7.24.4)(@types/node@20.12.7): + resolution: {integrity: sha512-G3qeRybVMUlfd36+ioqG5YsMgX+zDy3aeLk0qRqkjZ3zXvOgZ1OhjOFP7lEUcsMQ5nmcgwCCBqzk/UpAGiiDXg==} dependencies: axios: 1.6.8 jest: 29.7.0(@types/node@20.12.7)(ts-node@10.9.2) diff --git a/src/components/player-search.tsx b/src/components/player-search.tsx index 5aca3ad..6c2687f 100644 --- a/src/components/player-search.tsx +++ b/src/components/player-search.tsx @@ -1,6 +1,6 @@ "use client"; -import mcUtils from "mcutils-library"; +import { getPlayer } from "mcutils-library"; import Image from "next/image"; import Link from "next/link"; import { useState } from "react"; @@ -12,19 +12,20 @@ export default function PlayerSearch() { const [playerId, setPlayerId] = useState(null); const [player, setPlayer] = useState(null); - const handleLookup = () => { + const handleLookup = async () => { if (playerId === null || playerId.length <= 0) { toast.error("Please enter a player ID"); return; } - mcUtils.player - .getPlayer(playerId) - .then((response) => { - setPlayer(response.player); - }) - .catch(() => { - toast.error("Player not found"); - }); + try { + const cachedPlayer = await getPlayer(playerId); + const { player } = cachedPlayer; + + setPlayer(player); + } catch (error) { + toast.error("Unknown player"); + return; + } }; const handleKeyDown = (e: any) => { diff --git a/src/components/server-search.tsx b/src/components/server-search.tsx index 3804dd5..3f61168 100644 --- a/src/components/server-search.tsx +++ b/src/components/server-search.tsx @@ -1,7 +1,7 @@ "use client"; import { cn } from "@/common/utils"; -import mcUtils from "mcutils-library"; +import { getServer } 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"; @@ -14,19 +14,19 @@ export default function ServerSearch() { const [serverHostname, setServerHostname] = useState(null); const [server, setServer] = useState(null); - const handleLookup = () => { + const handleLookup = async () => { 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"); - }); + try { + const cachedServer = await getServer(ServerPlatform.Java, serverHostname); + const { server } = cachedServer; + setServer(server as JavaMinecraftServer); + } catch (error) { + toast.error("Unknown server"); + return; + } }; const handleKeyDown = (e: any) => {