import ErrorDisplay from "@/ui/error-display"; 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, IconX, } 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?order=1`).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)?.length === 0 ? (
No flights
) : ( Object.entries(flights.data) .reverse() .map(([year, months]) => ( <> <> {Object.entries(months) .reverse() .map(([month, days]) => ( {Object.entries(days) .reverse() .map(([, logs]) => ( <> {logs .reverse() .map((flight: FlightConciseSchema) => ( <> {flight.date} {`${Number( flight.time_total ).toFixed(1)} hr`} {flight.waypoint_from || flight.waypoint_to ? ( <> / {flight.waypoint_from ? ( {flight.waypoint_from} ) : ( "" )} {flight.waypoint_from && flight.waypoint_to ? ( ) : null} {flight.waypoint_to ? ( {flight.waypoint_to} ) : ( "" )} ) : null} } description={ {flight.comments ? flight.comments : "(No Comment)"} } rightSection={ flight.aircraft ? ( } color="gray" size="lg" > {flight.aircraft} ) : null } active={page === flight.id} /> ))} ))} ))} )) ) ) : flights.isLoading ? (
) : flights.isError ? ( ) : (
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 };