From d4bc7126fa56d48907a30898e41b6886fc97300c Mon Sep 17 00:00:00 2001 From: cris lombardo Date: Sat, 3 Feb 2024 12:05:14 -0500 Subject: [PATCH] chore: FRON-10 main filter url navigation --- src/app/[season]/[location]/page.tsx | 22 +++-------------- src/app/ui/MainFilters.tsx | 27 ++++++++++++-------- src/atoms/drivers.tsx | 19 +++++++++++--- src/atoms/races.tsx | 2 +- src/atoms/results.tsx | 37 ++++++++++++++-------------- src/atoms/sessions.tsx | 4 +-- src/lib/utils.tsx | 10 +++++--- 7 files changed, 64 insertions(+), 57 deletions(-) diff --git a/src/app/[season]/[location]/page.tsx b/src/app/[season]/[location]/page.tsx index 1bd34b6..3bc2d8b 100644 --- a/src/app/[season]/[location]/page.tsx +++ b/src/app/[season]/[location]/page.tsx @@ -25,34 +25,18 @@ export default function ResultsPage({ const [races] = useAtom(seasonRacesAtom); const [_, setRace] = useAtom(raceAtom); + // On Mount we need to update the race to use the url params useEffect(() => { setRace( - races.find((race) => race.Location === params.location) || 'All Races', + races.find((race) => race.Location.toLowerCase() === params.location) || + 'All Races', ); }, [races, params.location, setRace]); - // useAtom(fetchStandings); - // useAtom(fetchSessionResults); useAtom(fetchSessionResults); - // const [constructorStandings] = useAtom(constructorStandingsAtom); - // const [driverStandings] = useAtom(driverStandingsAtom); const [drivers] = useAtom(allDriversAtom); const [constructors] = useAtom(allConstructorAtom); - // const [driverStandings] = useAtom(driverStandingsAtom); - - // const [, handleRaceChange] = useAtom(handleRaceChangeAtom); - // const [allRaces] = useAtom(seasonRacesAtom) - - // if (!params) return <>; - // Get all - - // if (allRaces && allRaces.length > 0) { - // console.log('all races', allRaces[parseInt(params.round) - 1]) - - // handleRaceChange(allRaces[parseInt(params.round) - 1]); - // } - return (
{ const [, handleResultsSubmit] = useAtom(handleMainFilterSubmit); // useAtom(fetchSeasons); - // useAtom(toggleTelemetryDisableAtom); + useAtom(toggleTelemetryDisableAtom); // useAtom(fetchSessionResults); const changePath = (url: string) => { @@ -51,9 +54,10 @@ export const MainFilters = () => { if (pathname !== '/') router.push(url); }; - const handleSubmit = () => { + const handleSubmit = (e: React.MouseEvent) => { + const telemetry = (e.target as HTMLButtonElement).innerHTML === 'Telemetry'; const url = handleResultsSubmit(); - router.push('/' + url); + router.push('/' + url + (telemetry && '/telemetry')); }; return ( @@ -70,10 +74,11 @@ export const MainFilters = () => {
-