Skip to content

Commit

Permalink
Merge branch 'dev' into cypress
Browse files Browse the repository at this point in the history
  • Loading branch information
Lombardoc4 authored Jan 24, 2024
2 parents 4d5fa3b + 0aac508 commit c4667fd
Show file tree
Hide file tree
Showing 15 changed files with 482 additions and 245 deletions.
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm typecheck
npx lint-staged
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"cypress:open": "cypress open"
},
"dependencies": {
"axios": "latest",
"clsx": "latest",
"jotai": "latest",
"jotai-effect": "latest",
Expand Down
36 changes: 29 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 18 additions & 8 deletions src/app/MainFilters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import React from 'react';

import { Dropdown } from './ui/Dropdown';
import {
allSeasonsAtom,
driverAtom,
driversAtom,
fetchDriver,
Expand All @@ -19,10 +20,9 @@ import {
handleSeasonChangeAtom,
handleSessionChangeAtom,
raceAtom,
raceNamesDropdownAtom,
resultUrlAtom,
seasonAtom,
seasonsAtom,
seasonRacesAtom,
sessionAtom,
sessionsAtom,
telemetryDisableAtom,
Expand All @@ -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) => {
Expand All @@ -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 <Dropdown value={race} items={races} action={handleAction} />;

return (
<Dropdown
value={typeof race === 'string' ? race : race.EventName}
items={races.map((race) => race.EventName)}
action={handleAction}
/>
);
};

const DriverDropdown = ({ action }: actionT) => {
Expand Down
29 changes: 8 additions & 21 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -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'] });
Expand All @@ -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 (
<html lang='en'>
<body
className={clsx('min-h-screen px-4', inter.className, {
server: server,
// noServer: !server,
})}
>
<Nav />
{children}
<Provider>
<Nav />
{children}
</Provider>
</body>
</html>
);
Expand Down
Loading

0 comments on commit c4667fd

Please sign in to comment.