support searching by url
All checks were successful
deploy / deploy (push) Successful in 57s

This commit is contained in:
Lee 2023-10-20 19:53:33 +01:00
parent 7df628611b
commit 6c809696ea

@ -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;