diff --git a/.husky/pre-commit b/.husky/pre-commit index d24fdfc..c64f602 100755 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,4 +1,5 @@ #!/usr/bin/env sh . "$(dirname -- "$0")/_/husky.sh" +pnpm typecheck npx lint-staged diff --git a/package.json b/package.json index be19f98..787069e 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "cypress:open": "cypress open" }, "dependencies": { + "axios": "latest", "clsx": "latest", "jotai": "latest", "jotai-effect": "latest", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d379224..adf3882 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,6 +5,9 @@ settings: excludeLinksFromLockfile: false dependencies: + axios: + specifier: latest + version: 1.6.5 clsx: specifier: latest version: 2.0.0 @@ -1261,6 +1264,7 @@ packages: /asynckit@0.4.0: resolution: {integrity: sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q==} + dev: true /at-least-node@1.0.0: @@ -1302,6 +1306,16 @@ packages: engines: {node: '>=4'} dev: true + /axios@1.6.5: + resolution: {integrity: sha512-Ii012v05KEVuUoFWmMW/UQv9aRIc3ZwkWDcM+h5Il8izZCtRVpDUfwpoFf7eOtajT3QiGR4yDUx7lPqHJULgbg==} + dependencies: + follow-redirects: 1.15.4 + form-data: 4.0.0 + proxy-from-env: 1.1.0 + transitivePeerDependencies: + - debug + dev: false + /axobject-query@3.2.1: resolution: {integrity: sha512-jsyHu61e6N4Vbz/v18DHwWYKK0bSWLqn47eeDSKPB7m8tqMHF9YJ+mhIk2lVteyZrY8tnSj/jHOv4YiTCuCJgg==} dependencies: @@ -2958,6 +2972,16 @@ packages: resolution: {integrity: sha512-36yxDn5H7OFZQla0/jFJmbIKTdZAQHngCedGxiMmpNfEZM0sdEeT+WczLQrjK6D7o2aiyLYDnkw0R3JK0Qv1RQ==} dev: true + /follow-redirects@1.15.4: + resolution: {integrity: sha512-Cr4D/5wlrb0z9dgERpUL3LrmPKVDsETIJhaCMeDfuFYcqa5bldGV6wBsAN6X/vxlXQtFBMrXdXxdL8CbDTGniw==} + engines: {node: '>=4.0'} + peerDependencies: + debug: '*' + peerDependenciesMeta: + debug: + optional: true + dev: false + /for-each@0.3.3: resolution: {integrity: sha512-jqYfLp7mo9vIyQf8ykW2v7A+2N4QjeCeI5+Dz9XraiO1ign81wjiH7Fb9vSOWvQfNtmSa4H2RoQTrrXivdUZmw==} dependencies: @@ -2981,14 +3005,15 @@ packages: engines: {node: '>= 14.17'} dev: true - /form-data@2.3.3: - resolution: {integrity: sha512-1lLKB2Mu3aGP1Q/2eCOx0fNbRMe7XdwktwOruhfqqd0rIJWwN4Dh+E3hrPSlDCXnSR7UtZ1N38rVXm+6+MEhJQ==} - engines: {node: '>= 0.12'} + + /form-data@4.0.0: + resolution: {integrity: sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==} + engines: {node: '>= 6'} dependencies: asynckit: 0.4.0 combined-stream: 1.0.8 mime-types: 2.1.35 - dev: true + dev: false /formdata-polyfill@4.0.10: resolution: {integrity: sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==} @@ -4374,14 +4399,12 @@ packages: /mime-db@1.52.0: resolution: {integrity: sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==} engines: {node: '>= 0.6'} - dev: true /mime-types@2.1.35: resolution: {integrity: sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==} engines: {node: '>= 0.6'} dependencies: mime-db: 1.52.0 - dev: true /mimic-fn@2.1.0: resolution: {integrity: sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==} @@ -5189,7 +5212,6 @@ packages: /proxy-from-env@1.1.0: resolution: {integrity: sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==} - dev: true /psl@1.9.0: resolution: {integrity: sha512-E/ZsdU4HLs/68gYzgGTkMicWTLPdAftJLfJFlLUAAKZGkStNU72sZjT66SnMDVOfOWY/YAoiD7Jxa9iHvngcag==} diff --git a/src/app/MainFilters.tsx b/src/app/MainFilters.tsx index 4c43cb6..412e908 100644 --- a/src/app/MainFilters.tsx +++ b/src/app/MainFilters.tsx @@ -7,6 +7,7 @@ import React from 'react'; import { Dropdown } from './ui/Dropdown'; import { + allSeasonsAtom, driverAtom, driversAtom, fetchDriver, @@ -19,10 +20,9 @@ import { handleSeasonChangeAtom, handleSessionChangeAtom, raceAtom, - raceNamesDropdownAtom, resultUrlAtom, seasonAtom, - seasonsAtom, + seasonRacesAtom, sessionAtom, sessionsAtom, telemetryDisableAtom, @@ -36,7 +36,7 @@ type actionT = { const SeasonDropdown = ({ action }: actionT) => { const [season] = useAtom(seasonAtom); const [, handleSeasonChange] = useAtom(handleSeasonChangeAtom); - const [seasons] = useAtom(seasonsAtom); + const [seasons] = useAtom(allSeasonsAtom); const handleAction = (val: string) => { handleSeasonChange(val).then((url: string) => { @@ -51,16 +51,26 @@ const SeasonDropdown = ({ action }: actionT) => { const RaceDropdown = ({ action }: actionT) => { const [race] = useAtom(raceAtom); const [, handleRaceChange] = useAtom(handleRaceChangeAtom); - const [races] = useAtom(raceNamesDropdownAtom); + const [races] = useAtom(seasonRacesAtom); const handleAction = (val: string) => { - handleRaceChange(val).then((url: string) => { - action(url); - }); + const match = races.find((race) => race.EventName === val); + if (match) { + handleRaceChange(match).then((url: string) => { + action(url); + }); + } }; useAtom(fetchRaces); - return ; + + return ( + race.EventName)} + action={handleAction} + /> + ); }; const DriverDropdown = ({ action }: actionT) => { diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 943ce6a..39a22db 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -1,9 +1,11 @@ import clsx from 'clsx'; +import { Provider } from 'jotai'; import type { Metadata } from 'next'; import { Inter } from 'next/font/google'; import './globals.css'; +import { fetchAPI } from './lib/utils'; import { Nav } from './ui/Nav'; const inter = Inter({ subsets: ['latin'] }); @@ -13,40 +15,25 @@ export const metadata: Metadata = { description: 'Formula 1 Data Analysis', }; -const checkServer = async () => { - // Check if server exists - // Cannot use jotai on server component, aka RootLayout - const data = fetch('http://0.0.0.0:80', { cache: 'no-store' }).then( - (res) => { - if (!res.ok) { - return null; - } - return true; - }, - () => { - return null; - }, - ); - - return data; -}; - export default async function RootLayout({ children, }: { children: React.ReactNode; }) { - const server = await checkServer(); + const server = await fetchAPI('', true); return ( -