diff --git a/components/Sidebar.tsx b/components/Sidebar.tsx index f210431..99812c1 100644 --- a/components/Sidebar.tsx +++ b/components/Sidebar.tsx @@ -1,7 +1,10 @@ "use client"; +import { Airport } from "@/models/airport"; import { Event } from "@/models/event"; import { OnlineController } from "@/models/onlineController"; import { Response } from "@/models/response"; +import { PlaneLanding, PlaneTakeoff } from "lucide-react"; +import Link from "next/link"; import { useEffect, useState } from "react"; import Spinner from "./Spinner"; @@ -9,6 +12,7 @@ import Spinner from "./Spinner"; const Sideabr = () => { const [onlineControllers, setOnlineControllers] = useState([] as OnlineController[]); + const [airports, setAirports] = useState([] as Airport[]); const [events, setEvents] = useState([] as Event[]); const [loading, setLoading] = useState(true); @@ -23,6 +27,15 @@ const Sideabr = () => { return await response.json() as Response; }; + const fetchAirports = async () => { + const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/airports`); + if (!response.ok) { + const error = await response.json() as Response; + throw new Error(`Error fetching airports:\n${error.message}`); + } + return await response.json() as Response; + }; + const fetchEvents = async () => { const response = await fetch(`${process.env.NEXT_PUBLIC_API_URL}/events`); if (!response.ok) { @@ -40,6 +53,14 @@ const Sideabr = () => { console.log(`Error fetching online controllers:\n${error}`); }); + fetchAirports() + .then((response) => { + setAirports(response.data.slice(0, 5)); + }) + .catch((error) => { + console.log(`Error fetching airports:\n${error}`); + }); + fetchEvents() .then((response) => { setEvents(response.data); @@ -82,8 +103,44 @@ const Sideabr = () => { ) : } +
+
+
+ + Airports + +
+ {!loading ? ( + <> + {airports.length > 0 ? ( +
+ {airports.map(({ icao, arrivals, departures }) => ( +
+ {icao} +
+
+ + {arrivals} +
+
+ + {departures} +
+
+
+ ))} +
+ ) : ( +
No controllers online
+ )} + + ) : } +
+
+ Upcoming Events +
{!loading ? ( <>