'use client'; import { CaretDownIcon, CopyIcon, PersonIcon, ReloadIcon, } from '@radix-ui/react-icons'; import { AlertDialog, Button, Checkbox, DropdownMenu, Flex, Text, TextField, } from '@radix-ui/themes'; import { debounce } from 'lodash'; import { ChangeEvent, useEffect, useRef, useState } from 'react'; import PageWrapper from '../../../components/PageWrapper'; import { REGION_NAMES } from '../../../constants/regions'; import searchPlayersAcrossRegions, { AccountListWithServer, } from '../../../core/blitz/searchPlayersAcrossRegions'; import { resetSession, setSession, useSession } from '../../../stores/session'; import SessionPage from '../../embeds/session/page'; import { Menu } from './components/Menu'; import * as styles from './page.css'; export default function Page() { const input = useRef(null); const [searchResults, setSearchResults] = useState< AccountListWithServer | undefined >(undefined); const [showSearchResults, setShowSearchResults] = useState(false); const handleChange = debounce( async (event: ChangeEvent) => { if (event.target.value) { setSearchResults(await searchPlayersAcrossRegions(event.target.value)); } else { setSearchResults(undefined); setShowSearchResults(false); } }, 500, ); const session = useSession(); useEffect(() => { if (session.isTracking) input.current!.value = session.nickname; }, [session]); return (
{ event.stopPropagation(); if (event.target.value) { setShowSearchResults(true); setSearchResults(undefined); } else { setShowSearchResults(false); } handleChange(event); }} onBlur={(event) => { // TODO: remove this hack when https://github.com/radix-ui/primitives/issues/2193 is fixed if (showSearchResults) event.target.focus(); }} onKeyDown={(event) => { if (event.key === 'Escape') { setShowSearchResults(false); input.current?.blur(); } }} placeholder="Search for a player..." />
{searchResults === undefined ? ( Searching... ) : searchResults.length === 0 ? ( No results ) : ( searchResults?.map( ({ account_id: id, nickname, region }, index) => ( { setShowSearchResults(false); setSession(region, id, nickname); }} shortcut={REGION_NAMES[region]} > {nickname} ), ) )}
Are you sure you want to reset? This'll discard your current session and start tracking from scratch again. useSession.setState({ resetPrompt: !checked, }) } /> Don't ask me again Copied link to your clipboard Instructions for streamers: useSession.setState({ embedPrompt: !checked, }) } /> Don't show this again
); }