diff --git a/src/app.d.ts b/src/app.d.ts index 907a5ba..b5acccf 100644 --- a/src/app.d.ts +++ b/src/app.d.ts @@ -22,7 +22,6 @@ declare global { type Round = { value: number; - title: string; matches: MatchRow[]; }; @@ -83,4 +82,4 @@ interface ImportMeta { readonly env: ImportMetaEnv; } -export {}; +export { }; diff --git a/src/components/Bracket.svelte b/src/components/Bracket.svelte index 8e99132..24b1609 100644 --- a/src/components/Bracket.svelte +++ b/src/components/Bracket.svelte @@ -15,21 +15,13 @@ export let matches: Matches; export let readOnly: boolean = true; - const levels = [ - { value: 0, title: 'quarterfinals' }, - { value: 1, title: 'semifinals' }, - { value: 2, title: 'bronze' }, - { value: 3, title: 'gold' } - ]; - let rounds: Record = {}; const loadingPromise = $bracket.load().then(() => { bracket?.matches?.forEach((match) => { if (rounds[match.round] === undefined) { rounds[match.round] = { matches: [match], - value: levels[match.round].value, - title: levels[match.round].title ?? '' + value: match.round }; } else { rounds[match.round].matches.push(match); @@ -37,6 +29,15 @@ }); }); + const determineRoundName = (remainingRounds: number): string => { + console.log(remainingRounds); + if (remainingRounds === 1) { + return 'Championship'; // Custom name for the last round + } else { + return `Round ${numRounds - remainingRounds + 1}`; + } + }; + let matchesSubscription: RealtimeChannel | undefined; async function subscribeToMatches() { matchesSubscription = await bracket.subscribeToMatches(); @@ -54,6 +55,7 @@ error((err as HttpError).toString()); } } + $: numRounds = Object.keys(rounds).length; {#await loadingPromise} @@ -68,10 +70,11 @@ {:else}
- {#each Object.keys(rounds) as i} + {#each Object.keys(rounds) as i, index} {@const roundObj = rounds[Number(i)]} -
-

{roundObj.title}

+ {@const roundName = determineRoundName(numRounds - index)} +
+

{roundName}

    {#each roundObj.matches as match, index (index)} {@const team1Win =