import ErrorDisplay from "@/ui/error-display"; import { useApi } from "@/util/api"; import { useAircraft } from "@/util/hooks"; import { AircraftSchema, FlightConciseSchema } from "@/util/types"; import { NavLink, Text, Button, ScrollArea, Stack, Loader, Center, Badge, Group, Divider, Select, } from "@mantine/core"; import { randomId } from "@mantine/hooks"; import { Link, useLocation, useNavigate, useParams } from "@remix-run/react"; import { IconArrowRightTail, IconPlaneTilt, IconPlus, IconX, } from "@tabler/icons-react"; import { UseQueryResult, useQuery, useQueryClient, } from "@tanstack/react-query"; import { useEffect, useRef, useState } from "react"; function FlightsListDisplay({ flights, }: { flights: UseQueryResult<{ [year: string]: { [month: string]: { [day: string]: FlightConciseSchema[] }; }; }>; }) { const monthNames = [ "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", ]; const params = useParams(); useEffect(() => { console.log(params); if (params.id) { const selectedFlight = document.getElementById(`${params.id} navlink`); console.log(selectedFlight); selectedFlight?.scrollIntoView({ block: "center", inline: "center" }); } }, [flights.data]); 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={params.id === flight.id} /> ))} ))} ))} )) ) ) : flights.isLoading ? (
) : flights.isError ? ( ) : (
No Flights
)} ); } function AircraftFilter({ aircraft, setAircraft, query = "flights-list", }: { aircraft: string; setAircraft: (aircraft: string) => void; query?: string; }) { const getAircraft = useAircraft(); const queryClient = useQueryClient(); return (