From eac75976988d3f0c5d910ea8591f7e36e7e3bc68 Mon Sep 17 00:00:00 2001 From: Cris Lom <36197748+Lombardoc4@users.noreply.github.com> Date: Sat, 16 Mar 2024 15:27:09 -0400 Subject: [PATCH] refactor: FRON-40 reformat project structure and organization (#32) --- src/app/(features)/EventCountdown.tsx | 10 -- src/app/(features)/RaceTimeline.tsx | 76 ------------ src/app/(features)/StandingsTimeline.tsx | 68 ----------- .../[round]/[driver]/[session]/page.tsx | 10 -- .../[driver]/[session]/telemetry/page.tsx | 3 - src/app/[season]/[round]/[driver]/page.tsx | 10 -- src/app/[season]/[round]/page.tsx | 54 --------- src/app/[season]/layout.tsx | 26 ---- src/app/[season]/page.tsx | 58 --------- src/app/api/driver/router.ts | 0 src/app/api/event/router.ts | 0 src/app/api/middleware.ts | 12 ++ src/app/api/season/router.ts | 0 src/app/api/session/router.ts | 0 src/app/dashboard/layout.tsx | 19 +++ src/app/dashboard/page.tsx | 5 + src/app/layout.tsx | 10 +- src/app/page.tsx | 4 +- src/app/schedule/page.tsx | 10 ++ src/app/ui/Countdown.tsx | 18 --- src/app/ui/Nav.tsx | 114 ------------------ src/app/ui/Tabs.tsx | 57 --------- src/app/ui/Timeline.tsx | 53 -------- src/atoms/fetchCalls.tsx | 9 +- src/atoms/results.tsx | 2 +- src/components/Footer/index.tsx | 5 + .../ui => components/QueryNav}/Dropdown.tsx | 0 .../QueryNav/DropdownGroup.tsx} | 79 ++---------- src/components/QueryNav/index.tsx | 2 + src/components/SelectionData/DataTable.tsx | 0 src/components/SelectionData/Heatmap.tsx | 0 .../SelectionData/NextEvent.tsx} | 16 ++- .../SelectionData/QuerySelectionItem.tsx | 0 .../SelectionData/QuerySelectionList.tsx | 0 .../SelectionData}/RaceSchedule.tsx | 0 .../SelectionData/SelectionItem.tsx | 0 .../SelectionData/SelectionList.tsx | 0 src/components/SelectionData/index.tsx | 8 ++ src/components/Sidebar/index.ts | 0 src/components/TopNav/MainNav.tsx | 14 +++ src/components/TopNav/UserNav.tsx | 19 +++ src/components/TopNav/index.tsx | 19 +++ src/{ => lib}/constants.ts | 0 src/{utils => lib}/fakerData.tsx | 0 src/{utils => lib}/helpers.tsx | 2 +- src/{utils => lib}/placerholder-results.tsx | 0 src/{ => lib}/results.d.ts | 0 src/{utils => lib}/transformers.tsx | 2 +- 48 files changed, 149 insertions(+), 645 deletions(-) delete mode 100644 src/app/(features)/EventCountdown.tsx delete mode 100644 src/app/(features)/RaceTimeline.tsx delete mode 100644 src/app/(features)/StandingsTimeline.tsx delete mode 100644 src/app/[season]/[round]/[driver]/[session]/page.tsx delete mode 100644 src/app/[season]/[round]/[driver]/[session]/telemetry/page.tsx delete mode 100644 src/app/[season]/[round]/[driver]/page.tsx delete mode 100644 src/app/[season]/[round]/page.tsx delete mode 100644 src/app/[season]/layout.tsx delete mode 100644 src/app/[season]/page.tsx create mode 100644 src/app/api/driver/router.ts create mode 100644 src/app/api/event/router.ts create mode 100644 src/app/api/middleware.ts create mode 100644 src/app/api/season/router.ts create mode 100644 src/app/api/session/router.ts create mode 100644 src/app/dashboard/layout.tsx create mode 100644 src/app/dashboard/page.tsx create mode 100644 src/app/schedule/page.tsx delete mode 100644 src/app/ui/Countdown.tsx delete mode 100644 src/app/ui/Nav.tsx delete mode 100644 src/app/ui/Tabs.tsx delete mode 100644 src/app/ui/Timeline.tsx create mode 100644 src/components/Footer/index.tsx rename src/{app/ui => components/QueryNav}/Dropdown.tsx (100%) rename src/{app/ui/MainFilters.tsx => components/QueryNav/DropdownGroup.tsx} (60%) create mode 100644 src/components/QueryNav/index.tsx create mode 100644 src/components/SelectionData/DataTable.tsx create mode 100644 src/components/SelectionData/Heatmap.tsx rename src/{app/(features)/LandingNextEvent.tsx => components/SelectionData/NextEvent.tsx} (63%) create mode 100644 src/components/SelectionData/QuerySelectionItem.tsx create mode 100644 src/components/SelectionData/QuerySelectionList.tsx rename src/{app/(features) => components/SelectionData}/RaceSchedule.tsx (100%) create mode 100644 src/components/SelectionData/SelectionItem.tsx create mode 100644 src/components/SelectionData/SelectionList.tsx create mode 100644 src/components/SelectionData/index.tsx create mode 100644 src/components/Sidebar/index.ts create mode 100644 src/components/TopNav/MainNav.tsx create mode 100644 src/components/TopNav/UserNav.tsx create mode 100644 src/components/TopNav/index.tsx rename src/{ => lib}/constants.ts (100%) rename src/{utils => lib}/fakerData.tsx (100%) rename src/{utils => lib}/helpers.tsx (99%) rename src/{utils => lib}/placerholder-results.tsx (100%) rename src/{ => lib}/results.d.ts (100%) rename src/{utils => lib}/transformers.tsx (98%) diff --git a/src/app/(features)/EventCountdown.tsx b/src/app/(features)/EventCountdown.tsx deleted file mode 100644 index 9a0dc14..0000000 --- a/src/app/(features)/EventCountdown.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import { useAtom } from 'jotai'; - -import { nextEventTimeAtom } from '@/atoms/nextEvent'; - -import { Countdown } from '../ui/Countdown'; - -export const EventCountDown = () => { - const [nextEventCountdown] = useAtom(nextEventTimeAtom); - return ; -}; diff --git a/src/app/(features)/RaceTimeline.tsx b/src/app/(features)/RaceTimeline.tsx deleted file mode 100644 index 8dbd60f..0000000 --- a/src/app/(features)/RaceTimeline.tsx +++ /dev/null @@ -1,76 +0,0 @@ -import clsx from 'clsx'; -import { BsFillStarFill } from 'react-icons/bs'; - -import { - fastestLap, - formatDuration, - positionEnding, -} from '../../utils/helpers'; - -export const DriverResultsInfo = ({ - driver, - subEl = false, -}: { - driver: DriverResult; - subEl?: boolean; -}) => { - const durationPlus = driver.Position !== 1 ? '+' : ''; - return ( - <> - {/* Driver Standings */} -

- {positionEnding(driver.Position)} - {driver.Points} points - {fastestLap(driver.Position, driver.Points) && } -

-
-
-

- {driver.FullName} -

- {!subEl && ( -

- {driver.TeamName} -

- )} -
-
- {!subEl && ( -

- {driver.Time - ? durationPlus + formatDuration(driver.Time) - : driver.Status} -

- )} - - ); -}; - -export const ConstructorResultsInfo = ({ con }: { con: ConstructorResult }) => { - return ( - <> -

- {positionEnding(con.position)} - {con.points} points -

-

{con.name}

-
-
- {con.drivers && - con.drivers.map((driver: DriverResult) => ( -
- -
- ))} -
- - ); -}; diff --git a/src/app/(features)/StandingsTimeline.tsx b/src/app/(features)/StandingsTimeline.tsx deleted file mode 100644 index 862b8e0..0000000 --- a/src/app/(features)/StandingsTimeline.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import clsx from 'clsx'; - -import { positionEnding } from '../../utils/helpers'; - -export const DriverStandingInfo = ({ - driver, - subEl = false, -}: { - driver: DriverStandingSchema; - subEl?: boolean; -}) => { - return ( - <> -

- {positionEnding(driver.position)} -

- - {/* Driver Standings */} - {driver.Driver && ( -

- {driver.Driver.givenName} {driver.Driver.familyName} -

- )} - {!subEl && ( -

- {driver.Constructors.map(({ name }) => ( - {name} - ))} -

- )} -

Points: {driver.points}

-

Wins: {driver.wins}

- - ); -}; - -// constructor is a keyword cannot be used -export const ConstructorStandingInfo = ({ - con, -}: { - con: ConstructorStandingSchema; -}) => { - return ( - <> -

- {positionEnding(con.position)} -

- -

{con.Constructor.name}

-

Points: {con.points}

-

Wins: {con.wins}

-
-
- {con.Drivers && - con.Drivers.map((driver) => ( -
- -
- ))} -
- - ); -}; diff --git a/src/app/[season]/[round]/[driver]/[session]/page.tsx b/src/app/[season]/[round]/[driver]/[session]/page.tsx deleted file mode 100644 index 1f1a76c..0000000 --- a/src/app/[season]/[round]/[driver]/[session]/page.tsx +++ /dev/null @@ -1,10 +0,0 @@ -'use client'; - -import { useAtom } from 'jotai'; - -import { sessionAtom } from '@/atoms/sessions'; - -export default function SessionPage() { - const [session] = useAtom(sessionAtom); - return

{session}

; -} diff --git a/src/app/[season]/[round]/[driver]/[session]/telemetry/page.tsx b/src/app/[season]/[round]/[driver]/[session]/telemetry/page.tsx deleted file mode 100644 index 5103797..0000000 --- a/src/app/[season]/[round]/[driver]/[session]/telemetry/page.tsx +++ /dev/null @@ -1,3 +0,0 @@ -export default function TelemetryPage() { - return

Telemetry

; -} diff --git a/src/app/[season]/[round]/[driver]/page.tsx b/src/app/[season]/[round]/[driver]/page.tsx deleted file mode 100644 index d32f4c6..0000000 --- a/src/app/[season]/[round]/[driver]/page.tsx +++ /dev/null @@ -1,10 +0,0 @@ -'use client'; - -import { useAtom } from 'jotai'; - -import { driverAtom } from '@/atoms/drivers'; - -export default function DriverPage() { - const [driver] = useAtom(driverAtom); - return

{driver === 'All Drivers' ? driver : driver.FullName} - Race

; -} diff --git a/src/app/[season]/[round]/page.tsx b/src/app/[season]/[round]/page.tsx deleted file mode 100644 index 678ddd2..0000000 --- a/src/app/[season]/[round]/page.tsx +++ /dev/null @@ -1,54 +0,0 @@ -'use client'; - -import { useAtom } from 'jotai'; - -import { - ConstructorResultsInfo, - DriverResultsInfo, -} from '@/app/(features)/RaceTimeline'; -import { Tabs } from '@/app/ui/Tabs'; -import { Timeline, TimelineElement } from '@/app/ui/Timeline'; -import { allConstructorAtom } from '@/atoms/constructors'; -import { allDriversAtom } from '@/atoms/drivers'; -import { raceAtom } from '@/atoms/races'; - -export default function ResultsPage() { - const [drivers] = useAtom(allDriversAtom); - const [constructors] = useAtom(allConstructorAtom); - const [race] = useAtom(raceAtom); - - return ( -
-

{race === 'All Races' ? race : race.EventName}

- - {drivers?.map((driver, index, allDrivers) => ( - - - - ))} - , - - {constructors.map((con, index, allConstructors) => ( - - - - ))} - , - ]} - /> -
- ); -} diff --git a/src/app/[season]/layout.tsx b/src/app/[season]/layout.tsx deleted file mode 100644 index 4886cec..0000000 --- a/src/app/[season]/layout.tsx +++ /dev/null @@ -1,26 +0,0 @@ -'use client'; - -import { useAtom } from 'jotai'; -import Error from 'next/error'; - -import { serverErrorAtom } from '@/atoms/results'; - -import { MainFilters } from '../ui/MainFilters'; - -// Default Next Layout -export default function ResultsLayout({ - children, -}: { - children: React.ReactNode; -}) { - const [serverError] = useAtom(serverErrorAtom); - - return ( - <> -
- -
- {serverError ? : children} - - ); -} diff --git a/src/app/[season]/page.tsx b/src/app/[season]/page.tsx deleted file mode 100644 index b072698..0000000 --- a/src/app/[season]/page.tsx +++ /dev/null @@ -1,58 +0,0 @@ -'use client'; - -import { useAtom } from 'jotai'; - -import { fetchStandings } from '@/atoms/fetchCalls'; -import { - constructorStandingsAtom, - driverStandingsAtom, -} from '@/atoms/standings'; - -import { RaceSchedule } from '../(features)/RaceSchedule'; -import { - ConstructorStandingInfo, - DriverStandingInfo, -} from '../(features)/StandingsTimeline'; -import { Tabs } from '../ui/Tabs'; -import { Timeline, TimelineElement } from '../ui/Timeline'; - -export default function ResultsPage() { - const [constructorStandings] = useAtom(constructorStandingsAtom); - const [driverStandings] = useAtom(driverStandingsAtom); - useAtom(fetchStandings); - - return ( -
- , - - {driverStandings.map((driver, index, allDrivers) => ( - - - - ))} - , - - {constructorStandings.map((constructor, index, allConstructors) => ( - - - - ))} - , - ]} - /> -
- ); -} diff --git a/src/app/api/driver/router.ts b/src/app/api/driver/router.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/app/api/event/router.ts b/src/app/api/event/router.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/app/api/middleware.ts b/src/app/api/middleware.ts new file mode 100644 index 0000000..e8ae540 --- /dev/null +++ b/src/app/api/middleware.ts @@ -0,0 +1,12 @@ +import type { NextRequest } from 'next/server'; + +export function middleware(request: NextRequest) { + // Clone the request headers and set a new header `Auther` + const requestHeaders = new Headers(request.headers); + requestHeaders.set('Authorization', 'Bearer my-secret-token'); +} + +// See "Matching Paths" below to learn more +export const config = { + matcher: '/dashboard/:path*', +}; diff --git a/src/app/api/season/router.ts b/src/app/api/season/router.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/app/api/session/router.ts b/src/app/api/session/router.ts new file mode 100644 index 0000000..e69de29 diff --git a/src/app/dashboard/layout.tsx b/src/app/dashboard/layout.tsx new file mode 100644 index 0000000..4cc6d74 --- /dev/null +++ b/src/app/dashboard/layout.tsx @@ -0,0 +1,19 @@ +import { DropdownGroup } from '../../components/QueryNav'; + +export default function DashboardLayout({ + children, // will be a page or nested layout +}: { + children: React.ReactNode; +}) { + return ( + <> + + +
+ {/* */} + +
{children}
+
+ + ); +} diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx new file mode 100644 index 0000000..a8a7165 --- /dev/null +++ b/src/app/dashboard/page.tsx @@ -0,0 +1,5 @@ +// {serverError ? : children} + +export default function Page() { + return

Hello, Dashboard Page!

; +} diff --git a/src/app/layout.tsx b/src/app/layout.tsx index 097b50d..6279436 100644 --- a/src/app/layout.tsx +++ b/src/app/layout.tsx @@ -5,8 +5,10 @@ import { Inter } from 'next/font/google'; import './globals.css'; -import { Nav } from './ui/Nav'; -import { fetchAPI } from '../utils/helpers'; +import { Footer } from '@/components/Footer'; +import { TopNav } from '@/components/TopNav'; + +import { fetchAPI } from '../lib/helpers'; const inter = Inter({ subsets: ['latin'] }); @@ -27,13 +29,13 @@ export default async function RootLayout({ -