2023-09-18 22:32:21 +00:00
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import { CopyIcon, ListBulletIcon, ReloadIcon } from '@radix-ui/react-icons';
|
2023-09-18 23:05:19 +00:00
|
|
|
import { debounce } from 'lodash';
|
2023-09-18 23:25:24 +00:00
|
|
|
import { ChangeEvent, useRef, useState } from 'react';
|
2023-09-18 22:32:21 +00:00
|
|
|
import { Button } from '../../../components/Button';
|
|
|
|
|
import PageWrapper from '../../../components/PageWrapper';
|
|
|
|
|
import { SearchBar } from '../../../components/SearchBar';
|
2023-09-18 23:25:24 +00:00
|
|
|
import { REGION_NAMES } from '../../../constants/regions';
|
2023-09-18 23:05:19 +00:00
|
|
|
import { AccountListWithServer } from '../../../core/blitz/listPlayers';
|
2023-09-18 23:25:24 +00:00
|
|
|
import { theme } from '../../../stitches.config';
|
2023-09-18 22:32:21 +00:00
|
|
|
import * as styles from './page.css';
|
|
|
|
|
|
2023-09-18 21:55:40 +00:00
|
|
|
export default function Page() {
|
2023-09-18 23:05:19 +00:00
|
|
|
const input = useRef<HTMLInputElement>(null);
|
2023-09-18 23:25:24 +00:00
|
|
|
const [searchResults, setSearchResults] = useState<
|
|
|
|
|
AccountListWithServer | undefined
|
|
|
|
|
>(undefined);
|
|
|
|
|
const [showSearchResults, setShowSearchResults] = useState(false);
|
2023-09-18 23:05:19 +00:00
|
|
|
const handleChange = debounce(
|
|
|
|
|
async (event: ChangeEvent<HTMLInputElement>) => {
|
|
|
|
|
if (event.target.value) {
|
|
|
|
|
const players = await fetch(
|
|
|
|
|
`/api/list/players?search=${event.target.value}`,
|
|
|
|
|
).then((response) => response.json() as Promise<AccountListWithServer>);
|
|
|
|
|
|
2023-09-18 23:25:24 +00:00
|
|
|
setSearchResults(players);
|
2023-09-18 23:05:19 +00:00
|
|
|
} else {
|
|
|
|
|
// TODO
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
500,
|
|
|
|
|
);
|
|
|
|
|
|
2023-09-18 22:32:21 +00:00
|
|
|
return (
|
|
|
|
|
<PageWrapper>
|
|
|
|
|
<div className={styles.toolBar}>
|
2023-09-18 23:25:24 +00:00
|
|
|
<div style={{ flex: 1, boxSizing: 'border-box', position: 'relative' }}>
|
|
|
|
|
<SearchBar
|
|
|
|
|
ref={input}
|
|
|
|
|
style={{ width: '100%', boxSizing: 'border-box' }}
|
|
|
|
|
onChange={(event) => {
|
|
|
|
|
if (event.target.value) {
|
|
|
|
|
setShowSearchResults(true);
|
|
|
|
|
setSearchResults(undefined);
|
|
|
|
|
} else {
|
|
|
|
|
setShowSearchResults(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
handleChange(event);
|
|
|
|
|
}}
|
|
|
|
|
placeholder="Search for a player..."
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{showSearchResults && (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
position: 'absolute',
|
|
|
|
|
width: '100%',
|
|
|
|
|
top: '100%',
|
|
|
|
|
marginTop: 8,
|
|
|
|
|
flexDirection: 'column',
|
|
|
|
|
backgroundColor: theme.colors.componentNonInteractive,
|
|
|
|
|
border: theme.borderStyles.nonInteractive,
|
|
|
|
|
borderRadius: 4,
|
|
|
|
|
padding: 8,
|
|
|
|
|
boxSizing: 'border-box',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{searchResults === undefined ? (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignContent: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
color: theme.colors.textLowContrast,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
Searching...
|
|
|
|
|
</div>
|
|
|
|
|
) : searchResults.length === 0 ? (
|
|
|
|
|
<div
|
|
|
|
|
style={{
|
|
|
|
|
display: 'flex',
|
|
|
|
|
alignContent: 'center',
|
|
|
|
|
justifyContent: 'center',
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
color: theme.colors.textLowContrast,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
No results
|
|
|
|
|
</div>
|
|
|
|
|
) : (
|
|
|
|
|
searchResults?.map(({ account_id, nickname, region }) => (
|
|
|
|
|
<button
|
|
|
|
|
key={account_id}
|
|
|
|
|
className={styles.searchButton}
|
|
|
|
|
onClick={() => {
|
|
|
|
|
setShowSearchResults(false);
|
|
|
|
|
if (input.current) input.current.value = nickname;
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
<span
|
|
|
|
|
style={{
|
|
|
|
|
color: theme.colors.textHighContrast,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{nickname}
|
|
|
|
|
</span>
|
|
|
|
|
<span
|
|
|
|
|
style={{
|
|
|
|
|
color: theme.colors.textLowContrast,
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{REGION_NAMES[region]}
|
|
|
|
|
</span>
|
|
|
|
|
</button>
|
|
|
|
|
))
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
2023-09-18 22:32:21 +00:00
|
|
|
|
|
|
|
|
<div style={{ display: 'flex', gap: 8 }}>
|
2023-09-18 23:25:24 +00:00
|
|
|
<Button className={styles.toolbarButton} color="dangerous">
|
2023-09-18 22:32:21 +00:00
|
|
|
<ReloadIcon /> Reset
|
|
|
|
|
</Button>
|
2023-09-18 23:25:24 +00:00
|
|
|
<Button className={styles.toolbarButton}>
|
2023-09-18 22:32:21 +00:00
|
|
|
<CopyIcon /> Embed
|
|
|
|
|
</Button>
|
2023-09-18 23:25:24 +00:00
|
|
|
<Button className={styles.toolbarButton}>
|
2023-09-18 22:32:21 +00:00
|
|
|
<ListBulletIcon /> Options
|
|
|
|
|
</Button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</PageWrapper>
|
|
|
|
|
);
|
2023-09-18 21:55:40 +00:00
|
|
|
}
|