myheats

Live heats, scoring and leaderboard for sport events
git clone https://git.in0rdr.ch/myheats.git
Log | Files | Refs | Pull requests | README | LICENSE

commit 267a70e94511acc91a4be87ce05a39cf031a5a4e
parent 0a5a8d7df02960634909497d0263f3fcfc8f2ded
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Sun, 23 Jul 2023 09:46:15 +0200

feat: add checks for default to db

Diffstat:
Mschema/athletes.sql | 7++++---
Mschema/heats.sql | 7++++---
Msrc/Athletes.jsx | 27++++++---------------------
Msrc/Heats.jsx | 17++++-------------
Msrc/Leaderboard.jsx | 20+++++++-------------
5 files changed, 25 insertions(+), 53 deletions(-)

diff --git a/schema/athletes.sql b/schema/athletes.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version 15.1 --- Dumped by pg_dump version 15.2 +-- Dumped by pg_dump version 15.3 SET statement_timeout = 0; SET lock_timeout = 0; @@ -28,10 +28,11 @@ CREATE TABLE public.athletes ( id bigint NOT NULL, created_at timestamp with time zone DEFAULT now(), nr bigint, - firstname character varying, + firstname character varying NOT NULL, lastname character varying, birthday date, - school character varying + school character varying, + CONSTRAINT athletes_firstname_check CHECK ((length((firstname)::text) > 0)) ); diff --git a/schema/heats.sql b/schema/heats.sql @@ -3,7 +3,7 @@ -- -- Dumped from database version 15.1 --- Dumped by pg_dump version 15.2 +-- Dumped by pg_dump version 15.3 SET statement_timeout = 0; SET lock_timeout = 0; @@ -27,9 +27,10 @@ SET default_table_access_method = heap; CREATE TABLE public.heats ( id bigint NOT NULL, created_at timestamp with time zone DEFAULT now(), - name character varying, + name character varying NOT NULL, location character varying, - planned_start time without time zone + planned_start time without time zone, + CONSTRAINT heats_name_check CHECK ((length((name)::text) > 0)) ); diff --git a/src/Athletes.jsx b/src/Athletes.jsx @@ -10,11 +10,6 @@ async function addAthlete(e) { const formData = new FormData(e.target); const formJson = Object.fromEntries(formData.entries()); - if (defaultsSet(formJson)) { - alert('Check data of the new athlete, seems like the defaults') - return - } - // create new athlete const { error } = await supabase .from('athletes') @@ -33,16 +28,6 @@ async function addAthlete(e) { } } -function defaultsSet({nr, firstname, lastname, birthday, school}) { - return ( - nr === '00' - || firstname === 'Firstname *' - || lastname === 'Lastname' - || birthday === '0000-00-00' - || school === 'School/team' - ) -} - async function deleteAthlete(e, athleteId, athleteFirstName, athleteLastName) { e.preventDefault() @@ -78,8 +63,8 @@ function AthleteForm({session}) { <thead> <tr> <th>Created at</th> - <th>Start Nr.</th> - <th>Firstname</th> + <th>Start Nr. *</th> + <th>Firstname *</th> <th>Lastname</th> <th>Birthday</th> <th>School</th> @@ -101,13 +86,13 @@ function AthleteForm({session}) { <tr className='input'> <td className='right'><i>* required</i></td> <td data-title='Start Nr. *' className='right'> - <input type='number' name='nr' defaultValue='00' /> + <input type='number' name='nr' /> </td> <td data-title='Firstname *'> - <input type='text' name='firstname' defaultValue='Firstname *' /> + <input type='text' name='firstname' /> </td> <td data-title='Lastname'> - <input type='text' name='lastname' defaultValue='Lastname' /> + <input type='text' name='lastname' /> </td> <td data-title='Birthday' className='right'> <input @@ -115,7 +100,7 @@ function AthleteForm({session}) { name='birthday' /> </td> <td data-title='School'> - <input type='text' name='school' defaultValue='School/team' /> + <input type='text' name='school' /> </td> <td> <button type='submit'>&#43; new</button> diff --git a/src/Heats.jsx b/src/Heats.jsx @@ -11,11 +11,6 @@ async function addHeat(e) { const formData = new FormData(e.target); const formJson = Object.fromEntries(formData.entries()); - if (defaultsSet(formJson)) { - alert('Check data of the new heat, seems like the defaults') - return - } - // create new heat const { error } = await supabase .from('heats') @@ -34,10 +29,6 @@ async function addHeat(e) { } } -export function defaultsSet({name, location}) { - return (name === 'Name *' || location === 'Location') -} - async function deleteHeat(e, heatId, heatName) { e.preventDefault() @@ -72,7 +63,7 @@ function HeatForm({session}) { <thead> <tr> <th>Created at</th> - <th>Name</th> + <th>Name *</th> <th>Location</th> <th>Planned start</th> <th>New/delete</th> @@ -90,11 +81,11 @@ function HeatForm({session}) { ))} <tr className='input'> <td className='right'><i>* required</i></td> - <td data-title='Name'> - <input type='text' name='name' defaultValue='Name *' /> + <td data-title='Name *'> + <input type='text' name='name' /> </td> <td data-title='Location'> - <input type='text' name='location' defaultValue='Location' /> + <input type='text' name='location' /> </td> <td data-title='Planned start' className='right'> <input diff --git a/src/Leaderboard.jsx b/src/Leaderboard.jsx @@ -2,8 +2,6 @@ import { supabase } from './supabaseClient' import { Fragment, useEffect, useState, useRef } from 'react' import Select from 'react-select' -import { defaultsSet } from './Heats.jsx' - export async function getStartlistForHeats(heatIds) { return supabase.rpc('distinct_startlist', { 'heat_ids': heatIds }) } @@ -111,11 +109,6 @@ async function newHeatFromLeaderboard(e, {leaderboard, rankingComp, selectHeatRe const formData = new FormData(e.target); const formJson = Object.fromEntries(formData.entries()); - if (defaultsSet(formJson)) { - alert('Check data of the new heat, seems like the defaults') - return - } - // create new heat const { data, error } = await supabase .from('heats') @@ -129,7 +122,8 @@ async function newHeatFromLeaderboard(e, {leaderboard, rankingComp, selectHeatRe .select() if (error !== null) { - alert('Failed to create new heat. Verify that you are signed in.') + console.log(error.message) + alert(error.message) return } @@ -167,7 +161,7 @@ function NewHeatForm(leaderboard, rankingComp, selectHeatRef, selectRankRef) { <table> <thead> <tr> - <th>New heat name</th> + <th>New heat name *</th> <th>Location</th> <th>Planned start</th> <th>Include top N</th> @@ -176,11 +170,11 @@ function NewHeatForm(leaderboard, rankingComp, selectHeatRef, selectRankRef) { </thead> <tbody> <tr> - <td data-title='New heat name'> - <input type='text' name='name' defaultValue='Name *' /> + <td data-title='New heat name *'> + <input type='text' name='name' /> </td> <td data-title='Location'> - <input type='text' name='location' defaultValue='Location' /> + <input type='text' name='location' /> </td> <td data-title='Planned start'> <input @@ -188,7 +182,7 @@ function NewHeatForm(leaderboard, rankingComp, selectHeatRef, selectRankRef) { name='planned_start' /> </td> <td data-title='Include top N'> - <input type='number' name='size' defaultValue='10' /> + <input type='number' name='size' /> </td> <td> <button type='submit'>&#43; new</button>