commit c4933ae081248464c553f4b4e69d2270b593eb50
parent a5b72e3beac625cd7af51f03c4c5cb56c1c52d0e
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date: Wed, 8 Mar 2023 01:01:49 +0100
feat: add heat selector
Diffstat:
M | src/App.js | | | 58 | ++++++++++++++++++++++++++++++++++++++++++---------------- |
1 file changed, 42 insertions(+), 16 deletions(-)
diff --git a/src/App.js b/src/App.js
@@ -35,7 +35,13 @@ async function getRatingForHeatAndAthlete(heatId, athleteId) {
async function getRatingSummary(heatId) {
let startlist = {data: []}
- startlist = await getStartlistForHeat(heatId)
+ let newStartlist = await getStartlistForHeat(heatId)
+
+ if (newStartlist.error !== null) {
+ return []
+ }
+
+ startlist = newStartlist
return Promise.all(startlist.data.map(async i => {
let ratings = await getRatingForHeatAndAthlete(i.heat, i.athlete.id)
@@ -53,33 +59,53 @@ async function getRatingSummary(heatId) {
function App() {
const [leaderboard, setLeaderboard] = useState([]);
+ const [selectedHeat, setSelectedHeat] = useState([]);
+ const [selectedHeatIds, setSelectedHeatIds] = useState([]);
+ const [heats, setHeats] = useState([]);
useEffect(() => {
(async () => {
- let ratingSummary = await getRatingSummary(1)
+ let heatList = await supabase.from('heats').select()
+ setHeats(heatList.data)
+ let ratingSummary = await getRatingSummary(selectedHeatIds[0])
setLeaderboard(ratingSummary)
})();
- }, []);
+ }, [selectedHeatIds]);
// subscribe to ratings from judges and
// reload all ratings to refresh leaderboard
- const channel = supabase.channel('ratings')
- channel.on(
- 'postgres_changes',
- {
- event: '*',
- table: 'ratings',
- },
- async (payload) => {
- let ratingSummary = await getRatingSummary(1)
- setLeaderboard(ratingSummary)
- }
- ).subscribe()
+ // const channel = supabase.channel('ratings')
+ // channel.on(
+ // 'postgres_changes',
+ // {
+ // event: '*',
+ // table: 'ratings',
+ // },
+ // async (payload) => {
+ // let ratingSummary = await getRatingSummary(1)
+ // setLeaderboard(ratingSummary)
+ // }
+ // ).subscribe()
return (
<div className="App">
<header>
- <h1>Leaderboard Heat 1</h1>
+ <div>
+ Heats: <br />
+ <select multiple={true}
+ value={selectedHeat}
+ onChange={h => {
+ const options = [...h.target.selectedOptions];
+ const values = options.map(option => option.value);
+ setSelectedHeat(values)
+ setSelectedHeatIds(options.map(o => {return o.id}))
+ }}>
+ {heats.map(h => (
+ <option key={h.id} id={h.id}>{h.name}</option>
+ ))}
+ </select>
+ </div>
+ <h1>Leaderboard</h1>
</header>
<table>
<thead>