-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5c41730
commit dba5236
Showing
2 changed files
with
155 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
<script lang="ts"> | ||
import { base } from "$app/paths"; | ||
import { page } from "$app/stores"; | ||
import { PUBLIC_DATA_URL } from "$env/static/public"; | ||
import CatSpinner from "$lib/components/cat-spinner.svelte"; | ||
import Lede from "$lib/components/lede.svelte"; | ||
import Page from "$lib/components/page.svelte"; | ||
import { createBusy, type BusyState } from "$lib/kit"; | ||
import { | ||
formatScore, | ||
type ScoredPlayer, | ||
type TournamentType, | ||
} from "$lib/site"; | ||
import { getFriendlyErrorMsg } from "$lib/util"; | ||
interface ScoredMatchPlayer extends ScoredPlayer { | ||
gasUsed: number; | ||
} | ||
interface BracketData { | ||
tournamentId: string; | ||
time: Date; | ||
season: number; | ||
type: TournamentType; | ||
bracket: number; | ||
rankings: ScoredPlayer[], | ||
matches: Array<{ | ||
id: string; | ||
duration: number; | ||
rankings: ScoredMatchPlayer[]; | ||
}>; | ||
} | ||
let tournamentId: string | undefined; | ||
let seasonIdx: number | undefined; | ||
let bracketIdx: number | undefined; | ||
let data: BusyState<BracketData>; | ||
const dataAwait = createBusy<BracketData>(r => data = r); | ||
$: { | ||
parseQueryParams($page.url.searchParams); | ||
} | ||
$: { | ||
if (tournamentId) { | ||
dataAwait(async () => { | ||
const resp = await fetch(`${PUBLIC_DATA_URL}/results/bracket?${ | ||
new URLSearchParams({ | ||
tournament: tournamentId!, | ||
season: seasonIdx!.toString(), | ||
bracket: bracketIdx!.toString(), | ||
}) | ||
}`); | ||
if (!resp.ok) { | ||
console.error(await resp.text()); | ||
throw new Error(resp.statusText); | ||
} | ||
const bracket = await resp.json(); | ||
console.log(bracket); | ||
return { | ||
...bracket, | ||
time: new Date(bracket.time), | ||
}; | ||
}); | ||
} | ||
} | ||
function parseQueryParams(params: URLSearchParams): void { | ||
tournamentId = params.get('tournament') ?? undefined; | ||
seasonIdx = Number(params.get('season') ?? '1') - 1; | ||
bracketIdx = Number(params.get('bracket') ?? '1') - 1; | ||
} | ||
</script> | ||
|
||
<style lang="scss"> | ||
@use '../../lib/styles/global.scss'; | ||
.matches { | ||
.matches-grid { | ||
.match { | ||
h3 { | ||
margin-bottom: 0; | ||
} | ||
ol { | ||
margin-top: 0; | ||
} | ||
} | ||
} | ||
} | ||
</style> | ||
|
||
|
||
<Page title="Bracket Details"> | ||
{#if data instanceof Promise} | ||
<div class="loading"><CatSpinner /></div> | ||
{:else if data instanceof Error} | ||
<CatSpinner failed /> | ||
<div class="error">{getFriendlyErrorMsg(data)}</div> | ||
{:else if data} | ||
<Lede> | ||
<h1> | ||
Bracket {data.bracket + 1} | ||
</h1> | ||
<p> | ||
<a href={`${base}/tournament?id=${data.tournamentId}&season=${data.season + 1}`}> | ||
Season {data.season + 1} | ||
{#if data.type == 'scrimmage'}Market Day{:else}Grand Faire{/if} | ||
{data.time.toLocaleDateString()} | ||
</a> | ||
</p> | ||
</Lede> | ||
<section> | ||
<h2>Bracket Ranking</h2> | ||
<ol> | ||
{#each data.rankings as player (player.address)} | ||
<li> | ||
<a href={`${base}/player?name=${player.name}`}>{player.name}</a>: | ||
{formatScore(player.score)} | ||
</li> | ||
{/each} | ||
</ol> | ||
</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> | ||
{#each data.matches as match, i (match.id)} | ||
<div class="matches-grid"> | ||
<div class="match"> | ||
<h3>Match {i + 1}</h3> | ||
<ol> | ||
{#each match.rankings as player (player.address)} | ||
<li> | ||
<a href={`${base}/player?name=${player.name}`}>{player.name}</a>: | ||
{player.score.toFixed(3)}</li> | ||
{/each} | ||
</ol> | ||
</div> | ||
</div> | ||
{/each} | ||
</section> | ||
{/if} | ||
</Page> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters