import { useApi } from "@/util/api"; import { FlightConciseSchema } from "@/util/types"; import { NavLink, Text, Button, ScrollArea, Stack, Loader, Center, Badge, Group, Divider, } from "@mantine/core"; import { randomId } from "@mantine/hooks"; import { Link, useLocation, useNavigate } from "@remix-run/react"; import { IconArrowRightTail, IconPlaneTilt, IconPlus, } from "@tabler/icons-react"; import { UseQueryResult, useQuery } from "@tanstack/react-query"; function useFlights() { const client = useApi(); const flights = useQuery({ queryKey: ["flights-list"], queryFn: async () => await client.get(`/flights/by-date`).then((res) => res.data), }); return flights; } function FlightsListDisplay({ flights, page, }: { flights: UseQueryResult<{ [year: string]: { [month: string]: { [day: string]: FlightConciseSchema[] }; }; }>; page: string; }) { const monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ]; return ( <> {flights.data ? ( Object.entries(flights.data).map(([year, months]) => ( <> <> {Object.entries(months).map(([month, days]) => ( {Object.entries(days).map(([, logs]) => ( <> {logs.map((flight: FlightConciseSchema) => ( <> {flight.date} {`${Number(flight.time_total).toFixed( 1 )} hr`} {flight.waypoint_from || flight.waypoint_to ? ( / ) : null} {flight.waypoint_from ? ( {flight.waypoint_from} ) : ( "" )} {flight.waypoint_from && flight.waypoint_to ? ( ) : null} {flight.waypoint_to ? ( {flight.waypoint_to} ) : ( "" )} } description={ {flight.comments ? flight.comments : "(No Comment)"} } rightSection={ flight.aircraft ? ( } color="gray" size="lg" > {flight.aircraft} ) : null } active={page === flight.id} /> ))} ))} ))} )) ) : flights.isLoading ? (
) : (
No Flights
)} ); } export function FlightsList() { const location = useLocation(); const page = location.pathname.split("/")[3]; const flights = useFlights(); const navigate = useNavigate(); return ( ); } export function MobileFlightsList() { const location = useLocation(); const page = location.pathname.split("/")[3]; const flights = useFlights(); const navigate = useNavigate(); return ( ); } export default { FlightsList, MobileFlightsList };