diff --git a/src/app/tools/session/page.css.ts b/src/app/tools/session/page.css.ts index a15b1efa9..46e782ae4 100644 --- a/src/app/tools/session/page.css.ts +++ b/src/app/tools/session/page.css.ts @@ -1,4 +1,5 @@ import { style } from '@vanilla-extract/css'; +import { theme } from '../../../stitches.config'; export const toolBar = style({ '@media': { @@ -12,7 +13,7 @@ export const toolBar = style({ gap: 8, }); -export const button = style({ +export const toolbarButton = style({ '@media': { 'screen and (min-width: 640px)': { flex: 0, @@ -21,3 +22,19 @@ export const button = style({ flex: 1, }); + +export const searchButton = style({ + border: 'none', + background: 'none', + fontSize: 16, + display: 'flex', + padding: 8, + alignItems: 'center', + justifyContent: 'space-between', + cursor: 'pointer', + + ':hover': { + backgroundColor: theme.colors.componentInteractiveHover, + borderRadius: 4, + }, +}); diff --git a/src/app/tools/session/page.tsx b/src/app/tools/session/page.tsx index e6f09d53d..b93def02e 100644 --- a/src/app/tools/session/page.tsx +++ b/src/app/tools/session/page.tsx @@ -2,15 +2,21 @@ import { CopyIcon, ListBulletIcon, ReloadIcon } from '@radix-ui/react-icons'; import { debounce } from 'lodash'; -import { ChangeEvent, useRef } from 'react'; +import { ChangeEvent, useRef, useState } from 'react'; import { Button } from '../../../components/Button'; import PageWrapper from '../../../components/PageWrapper'; import { SearchBar } from '../../../components/SearchBar'; +import { REGION_NAMES } from '../../../constants/regions'; import { AccountListWithServer } from '../../../core/blitz/listPlayers'; +import { theme } from '../../../stitches.config'; 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) { @@ -18,11 +24,7 @@ export default function Page() { `/api/list/players?search=${event.target.value}`, ).then((response) => response.json() as Promise); - console.log( - players - .map((player) => `${player.region} - ${player.nickname}`) - .join('\n'), - ); + setSearchResults(players); } else { // TODO } @@ -33,21 +35,102 @@ export default function Page() { return (
- +
+ { + if (event.target.value) { + setShowSearchResults(true); + setSearchResults(undefined); + } else { + setShowSearchResults(false); + } + + handleChange(event); + }} + placeholder="Search for a player..." + /> + + {showSearchResults && ( +
+ {searchResults === undefined ? ( +
+ Searching... +
+ ) : searchResults.length === 0 ? ( +
+ No results +
+ ) : ( + searchResults?.map(({ account_id, nickname, region }) => ( + + )) + )} +
+ )} +
- - -