From 2a0d0e35b7c2741df5d1a4a46a218b037174d218 Mon Sep 17 00:00:00 2001 From: Kristian Gjertsen Date: Mon, 14 Sep 2026 14:49:59 +0200 Subject: [PATCH] feat: create DriverCard component and update App to display driver data --- src/App.css | 53 +++++++++++++++++++++++++++++++++++ src/App.tsx | 30 ++++++++++++-------- src/api/api.tsx | 14 ++++----- src/components/DriverCard.tsx | 21 ++++++++++++++ 4 files changed, 100 insertions(+), 18 deletions(-) create mode 100644 src/components/DriverCard.tsx diff --git a/src/App.css b/src/App.css index e69de29..da4c9bc 100644 --- a/src/App.css +++ b/src/App.css @@ -0,0 +1,53 @@ +body { + background-color: #272745; + color: white; + font-family: "Titillium Web", sans-serif; +} + +.driver-card { + background-color: #15151e; + border-radius: 30px; + + color: white; + font-family: "Titillium Web", sans-serif; + + height: 90px; + width: 500px; + + display: flex; + justify-content: space-between; + align-items: center; + + padding: 10px; + margin: 9px; +} + +.driver-card img { + height: 90px; + border-radius: 25px; +} + +.driver-card h1 { + font-size: 50px; +} +.driver-card h2 { + font-size: 22px; + font-weight: 400; +} + +.standing-drivers { + display: flex; + flex-direction: column; + align-items: flex-start; +} + +.standing-drivers { + display: flex; + flex-direction: column; + align-items: flex-start; + + width: fit-content; +} +.header { + align-self: center; +} diff --git a/src/App.tsx b/src/App.tsx index 15a3be5..44fe85b 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,31 +1,39 @@ import './App.css' -import api,{ type Driver } from './api/api' +import api, { type Driver } from './api/api' import { useEffect, useState } from "react"; +import DriverCard from './components/DriverCard' + function App() { const { getAllDrivers } = api() const [drivers, setDrivers] = useState([]) useEffect(() => { async function loadDrivers() { - const allDrivers = await getAllDrivers() - setDrivers(allDrivers) - console.log(allDrivers) + const allDrivers = await getAllDrivers() + setDrivers(allDrivers) + console.log(allDrivers) } loadDrivers() }, []) return ( <> -

WEB

- {drivers.map((driver) => ( -
-

{driver.full_name}

- -
- ))} +
+

F1 The Website

+ {drivers.map((driver) => ( + + + ))} +
) diff --git a/src/api/api.tsx b/src/api/api.tsx index 8736f99..5cae7e4 100644 --- a/src/api/api.tsx +++ b/src/api/api.tsx @@ -2,24 +2,24 @@ export interface Driver { broadcast_name: string; driver_number: number; - first_name : string, - last_name : string, + first_name: string, + last_name: string, full_name: string; headshot_url: string; meeting_key: number; - name_acronym : string; + name_acronym: string; session_key: number; team_colour: string; team_name: string; - } +} -export default function api(){ +export default function api() { const API = "https://api.openf1.org/v1" - async function getAllDrivers(){ + async function getAllDrivers() { const result = await fetch(`${API}/drivers?session_key=latest`); - if (!result.ok) { throw new Error("Failed to fetch drivers");} + if (!result.ok) { throw new Error("Failed to fetch drivers"); } const drivers: Driver[] = await result.json(); return drivers } diff --git a/src/components/DriverCard.tsx b/src/components/DriverCard.tsx new file mode 100644 index 0000000..12a6dc8 --- /dev/null +++ b/src/components/DriverCard.tsx @@ -0,0 +1,21 @@ +interface DriverProps { + name: string; + number: number; + headshot_url: string; + team_colour: string; + +} + + + +export default function DriverCard({ driver }: { driver: DriverProps }) { + + return ( +
+

{driver.number}

+

{driver.name}

+ {driver.name} +
+ ) +} +