commit 24d30713eebcdf96d8b20284bcbb3c318af357a0
parent 85d73ae80442cd29d6a89c4502eb4ea3b37bdcc4
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Fri, 31 Mar 2023 23:21:36 +0200
fix: heats can be null
Diffstat:
M | src/Leaderboard.js | | | 92 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
1 file changed, 47 insertions(+), 45 deletions(-)
diff --git a/src/Leaderboard.js b/src/Leaderboard.js
@@ -165,51 +165,53 @@ function Leaderboard() {
const heatList = await supabase.from('heats').select()
setHeats(heatList.data)
- // add options to select or rank by heat
- setHeatOpts(heats.map(h => {
- return {
- value: h.id,
- label: h.name
- }
- }))
-
- // add static ranking options
- const rankOptions = [
- {
- value: 'start',
- label: 'Start Nr.'
- }, {
- value: 'best',
- label: 'Best Heat'
- }, {
- value: 'worst',
- label: 'Worst Heat'
- }, {
- value: 'total',
- label: 'Total Sum (all heats)'
- }
- ]
-
- // add dynamic options to rank by best/worst heat
- const myHeatOpts = heatOpts.map(h => {
- return {
- value: h.value,
- label: "Sum " + h.label
- }
- })
-
- const groupedOptions = [
- {
- label: "Overall",
- options: rankOptions
- },
- {
- label: "Heat Sum",
- options: myHeatOpts
- }
- ];
-
- setRankOpts(groupedOptions)
+ if (heats) {
+ // add options to select or rank by heat
+ setHeatOpts(heats.map(h => {
+ return {
+ value: h.id,
+ label: h.name
+ }
+ }))
+
+ // add static ranking options
+ const rankOptions = [
+ {
+ value: 'start',
+ label: 'Start Nr.'
+ }, {
+ value: 'best',
+ label: 'Best Heat'
+ }, {
+ value: 'worst',
+ label: 'Worst Heat'
+ }, {
+ value: 'total',
+ label: 'Total Sum (all heats)'
+ }
+ ]
+
+ // add dynamic options to rank by best/worst heat
+ const myHeatOpts = heatOpts.map(h => {
+ return {
+ value: h.value,
+ label: "Sum " + h.label
+ }
+ })
+
+ const groupedOptions = [
+ {
+ label: "Overall",
+ options: rankOptions
+ },
+ {
+ label: "Heat Sum",
+ options: myHeatOpts
+ }
+ ];
+
+ setRankOpts(groupedOptions)
+ }
const ratingSummary = await getRatingSummary(heatSelection.map(h => h.value))
setLeaderboard(ratingSummary)