Skip to content

Commit

Permalink
cleanup ui for updating matches
Browse files Browse the repository at this point in the history
  • Loading branch information
craigkai committed Jan 2, 2024
1 parent cc60e0b commit aa07f4c
Showing 1 changed file with 47 additions and 35 deletions.
82 changes: 47 additions & 35 deletions src/lib/components/tournament/Match.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import type { Tournament } from '$lib/tournament';
import { Tooltip, Label, Input } from 'flowbite-svelte';
import { error, success } from '$lib/toast';
import { CheckSolid, CloseSolid } from 'flowbite-svelte-icons';
export let match: MatchRow;
export let tournament: Tournament;
Expand All @@ -12,7 +13,7 @@
async function updateMatch() {
try {
await tournament.updateMatch(match);
success('Match updated');
success(`Match ${match.matches_team1_fkey.name} vs ${match.matches_team2_fkey.name} updated`);
} catch (err: any) {
error(err?.body?.message ?? `Something went wrong: ${err}`);
}
Expand All @@ -23,61 +24,72 @@

<!-- svelte-ignore a11y-click-events-have-key-events -->
<!-- svelte-ignore a11y-no-static-element-interactions -->
<div
on:click={() => (editing = true)}
on:keydown={(e) => {
if (e.key === 'Enter' || e.key === ' ') {
editing = true;
}
}}
>
{#if !readOnly && editing}
<Label for="team1-score-input" class="block mb-2">{match.matches_team1_fkey.name} score:</Label>
{#if !readOnly && editing}
<div class="flex flex-row">
<Label for="team1-score-input" class="block m-2">{match.matches_team1_fkey.name}:</Label>
<Input
id="team1-score-input"
size="md"
bind:value={match.team1_score}
on:blur={() => (editing = false)}
on:keydown={(e) => {
if (e?.key === 'Enter') {
updateMatch();
editing = false;
} else if (e?.key === 'ESC') {
editing = false;
}
}}
/>

<Label for="team2-score-input" class="block mb-2">{match.matches_team2_fkey.name} score:</Label>
<Label for="team2-score-input" class="block m-2">{match.matches_team2_fkey.name}:</Label>
<Input
id="team2-score-input"
size="sm"
bind:value={match.team2_score}
on:blur={() => (editing = false)}
on:keydown={(e) => {
if (e?.key === 'Enter') {
updateMatch();
editing = false;
} else if (e?.key === 'ESC') {
editing = false;
}
}}
/>
{:else}
<div>
<span
class="p-2 rounded"
class:bg-green-300={hasMatchResult && match?.team1_score > match?.team2_score}
class:bg-red-300={hasMatchResult && match?.team2_score > match?.team1_score}
>
{match?.matches_team1_fkey?.name}</span
>
vs
<span
class="p-2 rounded"
class:bg-green-300={hasMatchResult && match?.team2_score > match?.team1_score}
class:bg-red-300={hasMatchResult && match?.team1_score > match?.team2_score}
>{match?.matches_team2_fkey?.name}</span
>
</div>
{#if hasMatchResult}
<Tooltip>{match?.team1_score} to {match?.team2_score}</Tooltip>
{/if}

<CheckSolid
color="green"
class="m-2 cursor-pointer"
on:click={() => {
updateMatch();
editing = false;
}}
/>
<CloseSolid color="red" class="m-2 cursor-pointer" on:click={() => (editing = false)} />
</div>
{:else}
<div
on:click={() => {
if (!editing) {
editing = true;
}
}}
>
<span
class="p-2 rounded"
class:bg-green-300={hasMatchResult && match?.team1_score > match?.team2_score}
class:bg-red-300={hasMatchResult && match?.team2_score > match?.team1_score}
>
{match?.matches_team1_fkey?.name}</span
>
vs
<span
class="p-2 rounded"
class:bg-green-300={hasMatchResult && match?.team2_score > match?.team1_score}
class:bg-red-300={hasMatchResult && match?.team1_score > match?.team2_score}
>{match?.matches_team2_fkey?.name}</span
>
</div>
{#if hasMatchResult}
<Tooltip>{match?.team1_score} to {match?.team2_score}</Tooltip>
{/if}
</div>
{/if}

1 comment on commit aa07f4c

@vercel
Copy link

@vercel vercel bot commented on aa07f4c Jan 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

volleyman – ./

volleyman.vercel.app
volleyman-craigkai.vercel.app
volleyman-git-main-craigkai.vercel.app

Please sign in to comment.