From aa07f4cbf813a29523fdbe252407be096b2a2abb Mon Sep 17 00:00:00 2001 From: Craig Kaiser Date: Tue, 2 Jan 2024 14:17:21 -0500 Subject: [PATCH] cleanup ui for updating matches --- src/lib/components/tournament/Match.svelte | 82 +++++++++++++--------- 1 file changed, 47 insertions(+), 35 deletions(-) diff --git a/src/lib/components/tournament/Match.svelte b/src/lib/components/tournament/Match.svelte index 7ac261c..d8d1039 100644 --- a/src/lib/components/tournament/Match.svelte +++ b/src/lib/components/tournament/Match.svelte @@ -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; @@ -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}`); } @@ -23,61 +24,72 @@ -
(editing = true)} - on:keydown={(e) => { - if (e.key === 'Enter' || e.key === ' ') { - editing = true; - } - }} -> - {#if !readOnly && editing} - +{#if !readOnly && editing} +
+ (editing = false)} on:keydown={(e) => { if (e?.key === 'Enter') { updateMatch(); editing = false; + } else if (e?.key === 'ESC') { + editing = false; } }} /> - + (editing = false)} on:keydown={(e) => { if (e?.key === 'Enter') { updateMatch(); editing = false; + } else if (e?.key === 'ESC') { + editing = false; } }} /> - {:else} -
- match?.team2_score} - class:bg-red-300={hasMatchResult && match?.team2_score > match?.team1_score} - > - {match?.matches_team1_fkey?.name} - vs - match?.team1_score} - class:bg-red-300={hasMatchResult && match?.team1_score > match?.team2_score} - >{match?.matches_team2_fkey?.name} -
- {#if hasMatchResult} - {match?.team1_score} to {match?.team2_score} - {/if} + + { + updateMatch(); + editing = false; + }} + /> + (editing = false)} /> +
+{:else} +
{ + if (!editing) { + editing = true; + } + }} + > + match?.team2_score} + class:bg-red-300={hasMatchResult && match?.team2_score > match?.team1_score} + > + {match?.matches_team1_fkey?.name} + vs + match?.team1_score} + class:bg-red-300={hasMatchResult && match?.team1_score > match?.team2_score} + >{match?.matches_team2_fkey?.name} +
+ {#if hasMatchResult} + {match?.team1_score} to {match?.team2_score} {/if} -
+{/if}