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 ce7d3425aa00af6e70a241a5ab73f3297e49d0b7
parent 084f41ef32b19bdb448f9f6c8a98852bf30f4e52
Author: Andreas Gruhler <andreas.gruhler@adfinis.com>
Date:   Fri, 17 Mar 2023 22:08:23 +0100

fix: simplify session passing

Diffstat:
MREADME.md | 4++--
Msrc/App.js | 11++++-------
Msrc/Rate.js | 12++++++------
3 files changed, 12 insertions(+), 15 deletions(-)

diff --git a/README.md b/README.md @@ -83,7 +83,8 @@ Sign up process for new judges: * The UUID is referenced automatically in the `judges` table, row can be amended with name of the judge Sign in process: -* For sign in, the judge enters her email adress and receives a login link which is valid for 1h +* For sign in, the judge enters her email adress and receives a login link +* The login information is stored in the browser session until sign out ## Bulk Import/Export @@ -104,7 +105,6 @@ To export data to local csv: ## TODO -* Magic link TTL * Rating UI * Delete/Edit heats diff --git a/src/App.js b/src/App.js @@ -10,14 +10,14 @@ const Leaderboard = lazy(() => import('./Leaderboard')); document.title = process.env.REACT_APP_DOC_TITLE ? process.env.REACT_APP_DOC_TITLE : 'My Heats' -function Layout(session) { +function Layout({session}) { return ( <div> <nav> <ul> <li><Link to="/leaderboard">Leaderboard</Link></li> <li><Link to="/rate">Rate</Link></li> - {session.session ? <li><button onClick={() => supabase.auth.signOut()}>Sign out {session.session.user.email}</button></li> : ""} + {session ? <li><button onClick={() => supabase.auth.signOut()}>Sign out {session.user.email}</button></li> : ""} </ul> </nav> <Outlet /> @@ -41,19 +41,16 @@ function App() { const [session, setSession] = useState(null) useEffect(() => { + // Returns the session, refreshing it if necessary supabase.auth.getSession().then(({ data: { session } }) => { setSession(session) - // const { data, error } = supabase.auth.setSession({ - // access_token: session.access_token, - // refresh_token: session.refresh_token - // }) }) supabase.auth.onAuthStateChange((_event, session) => { setSession(session) }) }, []) - + return ( <div className="App"> <Router> diff --git a/src/Rate.js b/src/Rate.js @@ -14,7 +14,7 @@ async function updateRating(rating, heatId, athleteId, userId) { }) } -function RatingForm(session) { +function RatingForm({session}) { const [heats, setHeats] = useState([]) const [heatSelection, setHeatSelection] = useState(0) const [athleteOpts, setAthleteOpts] = useState([]) @@ -56,7 +56,7 @@ function RatingForm(session) { const currentRating = await supabase.from('ratings').select() .eq('heat', heatSelection.value) .eq('athlete', athleteSelection.value) - .eq('judge', session.session.user.id) + .eq('judge', session.user.id) if (rating === 0 && currentRating.data?.length > 0) { // fallback to current rating when no rating was given @@ -66,10 +66,10 @@ function RatingForm(session) { updateRating(rating, heatSelection.value, athleteSelection.value, - session.session.user.id) + session.user.id) } })(); - }, [heatSelection, athleteSelection, session.session.user.id, rating]); + }, [heatSelection, athleteSelection, session.user.id, rating]); return ( <div> @@ -95,10 +95,10 @@ function RatingForm(session) { ) } -function Rate(session) { +function Rate({session}) { return ( <div> - {!session.session ? <Auth /> : <RatingForm key={session.session.user.id} session={session.session} />} + {!session ? <Auth /> : <RatingForm key={session.user.id} session={session} />} </div> ) }