"use client"; import { formatNumberWithCommas } from "@/common/number-utils"; import { zodResolver } from "@hookform/resolvers/zod"; import Link from "next/link"; import { useState } from "react"; import { useForm } from "react-hook-form"; import { z } from "zod"; import { Avatar, AvatarFallback, AvatarImage } from "../ui/avatar"; import { Button } from "../ui/button"; import { Form, FormControl, FormField, FormItem, FormLabel } from "../ui/form"; import { Input } from "../ui/input"; import { ScrollArea } from "../ui/scroll-area"; import ScoreSaberPlayerToken from "@ssr/common/types/token/scoresaber/score-saber-player-token"; import { scoresaberService } from "@ssr/common/service/impl/scoresaber"; const formSchema = z.object({ username: z.string().min(3).max(50), }); export default function SearchPlayer() { const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { username: "", }, }); const [results, setResults] = useState(); const [loading, setLoading] = useState(false); async function onSubmit({ username }: z.infer) { setLoading(true); setResults(undefined); // Reset results const results = await scoresaberService.searchPlayers(username); setResults(results?.players); setLoading(false); } return (
{/* Search */}
( Username )} /> {/* Results */} {loading == true && (

Loading...

)} {results !== undefined && (
{results?.map(player => { return ( {player.name.at(0)}

{player.name}

#{formatNumberWithCommas(player.rank)}

); })}
)}
); }