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 f6ef1ce1029f6350d3692d0642741081f248895d
parent 5d07234ebb3b637e9e8e964f25a761b1cdbc1b6b
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Sun, 18 Aug 2024 13:24:23 +0200

feat(athletes): export to csv

Diffstat:
Msrc/Athletes.jsx | 13+++++++++++++
Msrc/Heats.jsx | 2+-
Msrc/utils.js | 19+++++++++++++++++++
3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/src/Athletes.jsx b/src/Athletes.jsx @@ -1,5 +1,6 @@ import { lazy, useEffect, useState } from 'react' import { supabase } from './supabaseClient' +import { exportAthletesToCSV } from './utils' const Auth = lazy(() => import('./Auth')) @@ -41,6 +42,17 @@ async function deleteAthlete(e, athleteId, athleteFirstName, athleteLastName) { } } +// export athletes +function ExportForm() { + return ( + <div className='exportForm'> + <form method='post' onSubmit={e => exportAthletesToCSV(e)}> + <button type='submit'>&#9663; export</button> + </form> + </div> + ) +} + function AthleteForm({session}) { const [loading, setLoading] = useState(false) const [athletes, setAthletes] = useState([]) @@ -109,6 +121,7 @@ function AthleteForm({session}) { </tbody> </table> </form> + <ExportForm /> </div> ) } diff --git a/src/Heats.jsx b/src/Heats.jsx @@ -43,7 +43,7 @@ async function deleteHeat(e, heatId, heatName) { } // export heats -function ExportForm({heats}) { +function ExportForm() { return ( <div className='exportForm'> <form method='post' onSubmit={e => exportHeatsToCSV(e)}> diff --git a/src/utils.js b/src/utils.js @@ -19,6 +19,25 @@ export const exportHeatsToCSV = async function(e) { exportCSV(data, "heats") } +export const exportAthletesToCSV = async function(e) { + e.preventDefault() + + const { data, error } = await supabase + .from('athletes') + .select('created_at,nr,firstname,lastname,birthday,school') + .csv() + + if (error !== null) { + alert(error.message) + return + } else if (data.length === 0) { + alert('No athletes yet, nothing to export') + return + } + + exportCSV(data, "athletes") +} + export const exportLeaderboardToCSV = async function(e, leaderboard, heatSelection, rankingComp) { e.preventDefault()