From 6c809696eaa78fb34a9d3bde42f7d287257bd618 Mon Sep 17 00:00:00 2001 From: Liam Date: Fri, 20 Oct 2023 19:53:33 +0100 Subject: [PATCH] support searching by url --- src/components/SearchPlayer.tsx | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/components/SearchPlayer.tsx b/src/components/SearchPlayer.tsx index bb2c428..15013b8 100644 --- a/src/components/SearchPlayer.tsx +++ b/src/components/SearchPlayer.tsx @@ -2,7 +2,7 @@ import { ScoresaberPlayer } from "@/schemas/scoresaber/player"; import { formatNumber } from "@/utils/number"; -import { searchByName } from "@/utils/scoresaber/api"; +import { getPlayerInfo, searchByName } from "@/utils/scoresaber/api"; import { MagnifyingGlassIcon } from "@heroicons/react/20/solid"; import clsx from "clsx"; import { useEffect, useState } from "react"; @@ -22,6 +22,15 @@ export default function SearchPlayer() { }, [search]); async function searchPlayer(search: string) { + if (search.startsWith("https://scoresaber.com/u/")) { + const id = search.split("/").pop(); + if (id == undefined) return; + + const player = await getPlayerInfo(id); + if (player == undefined) return; + + setPlayers([player]); + } const players = await searchByName(search); if (players == undefined) return;