Skip to content

Commit

Permalink
add username filter to brackets
Browse files Browse the repository at this point in the history
  • Loading branch information
merklejerk committed Jun 20, 2024
1 parent f73bbcd commit 171e660
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 10 deletions.
35 changes: 26 additions & 9 deletions src/routes/(app)/bracket/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
let bracketIdx: number | undefined;
let data: BusyState<BracketData>;
const dataAwait = createBusy<BracketData>(r => data = r);
let filterUserName: string | null = null;
$: {
parseQueryParams($page.url.searchParams);
Expand Down Expand Up @@ -73,12 +74,27 @@
seasonIdx = Number(params.get('season') ?? '1') - 1;
bracketIdx = Number(params.get('bracket') ?? '1') - 1;
}
function testUserNameFilter(filter: string | null, names: string[]): boolean {
const needle = (filter ?? '').replaceAll(/\s/g, '');
if (!needle) {
return true;
}
return names.some(n => n.toLocaleLowerCase().includes(needle));
}
</script>

<style lang="scss">
@use '../../../lib/styles/global.scss';
.matches {
.summary {
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
flex-wrap: wrap;
}
.matches-grid {
display: flex;
flex-wrap: wrap;
Expand All @@ -102,10 +118,6 @@
font-size: 0.8em;
}
.date {
float: right;
}
</style>

<Page title="Bracket Details">
Expand Down Expand Up @@ -144,13 +156,17 @@
</section>
<section class="matches">
<h2>Matches</h2>
<div>
Players: {data.rankings.length},
Matches: {data.matches.length}
({data.matches.length / Math.ceil(data.rankings.length / 4)}pp)
<div class="summary">
<div>
Players: {data.rankings.length},
Matches: {data.matches.length}
({data.matches.length / Math.ceil(data.rankings.length / 4)}pp)
</div>
<input type="text" class="filter" placeholder="username" bind:value={filterUserName} />
</div>
<div class="matches-grid">
{#each data.matches as match, i (match.id)}
{#each data.matches as match, i (match.id)}
{#if testUserNameFilter(filterUserName, match.rankings.map(r => r.name))}
<div class="match">
<h3>
Match {i + 1}
Expand All @@ -173,6 +189,7 @@
{/each}
</ol>
</div>
{/if}
{/each}
</div>
</section>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/(app)/player/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@
return s as Hex;
}
async function populateCodeInputFromFileInput(): void {
async function populateCodeInputFromFileInput(): Promise<void> {
const file = fileInputButton.files?.[0];
if (!file) {
rawCode = '0x';
Expand Down

0 comments on commit 171e660

Please sign in to comment.