import { useEffect, useState } from 'react' import { useNavigate, useParams } from 'react-router-dom' import { api } from './api' import { ReviewDashboard } from './ReviewDashboard' import { useStore } from './store' /** * Route: /session/:sessionId * * Loads session data from the API on mount so the page survives a hard refresh * or a direct link (e.g. from a blog post). If the session ID is not found the * user is redirected back to the upload page with a clear error message. */ export function SessionPage() { const { sessionId } = useParams<{ sessionId: string }>() const navigate = useNavigate() const setSession = useStore((s) => s.setSession) const sessionData = useStore((s) => s.sessionData) const [loading, setLoading] = useState(false) const [error, setError] = useState(null) useEffect(() => { if (!sessionId) { navigate('/') return } // If the store already has data for this exact session (just navigated from // the upload page), skip the API call. if (sessionData?.session_id === sessionId) return setLoading(true) api.getSession(sessionId) .then((data) => { setSession(data) setLoading(false) }) .catch(() => { setError(`Session "${sessionId.slice(0, 8)}…" not found or has expired.`) setLoading(false) }) }, [sessionId]) // eslint-disable-line react-hooks/exhaustive-deps if (loading) { return (

Loading session…

) } if (error) { return (

{error}

) } if (!sessionId) return null return }