From 9b8552196450f31b2efd09c97564f68a92d9f57f Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 20 Oct 2023 12:07:17 +0100 Subject: [PATCH] fix searching --- src/components/SearchPlayer.tsx | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/src/components/SearchPlayer.tsx b/src/components/SearchPlayer.tsx index f39355c..e0cff3d 100644 --- a/src/components/SearchPlayer.tsx +++ b/src/components/SearchPlayer.tsx @@ -1,6 +1,7 @@ "use client"; import { ScoresaberPlayer } from "@/schemas/scoresaber/player"; +import { searchByName } from "@/utils/scoresaber/api"; import { MagnifyingGlassIcon } from "@heroicons/react/20/solid"; import clsx from "clsx"; import { useEffect, useState } from "react"; @@ -19,15 +20,11 @@ export default function SearchPlayer() { searchPlayer(search); }, [search]); - function searchPlayer(search: string) { - fetch(`/api/player/search?name=${search}`).then(async (reponse) => { - const json = await reponse.json(); + async function searchPlayer(search: string) { + const players = await searchByName(search); + if (players == undefined) return; - if (json.error || !json.players) { - setPlayers([]); // Clear players - } - setPlayers(json.players); // Set players - }); + setPlayers(players); } function handleSubmit(e: React.FormEvent) { @@ -54,14 +51,14 @@ export default function SearchPlayer() {
0 ? "flex" : "hidden", )} > {players.map((player: ScoresaberPlayer) => (