Updated airports, admin page

This commit is contained in:
2023-11-20 17:08:31 -05:00
parent d45ed73eed
commit ac46759fca
4 changed files with 37 additions and 15 deletions

View File

@@ -1458,7 +1458,7 @@
"local_code": "0R1" "local_code": "0R1"
}, },
{ {
"icao": "K0R3", "icao": "KIYA",
"category": "small_airport", "category": "small_airport",
"full_name": "Abbeville Chris Crusta Memorial Airport", "full_name": "Abbeville Chris Crusta Memorial Airport",
"point": "point":

View File

@@ -21,11 +21,6 @@ interface GetAirportsProps {
limit?: number; limit?: number;
} }
export async function getAirportsCount() {
const response = await getRequest('airports/count');
return response?.json() || { data: 0 };
}
export async function getAirports({ export async function getAirports({
bounds, bounds,
category, category,

View File

@@ -7,6 +7,17 @@ export enum AirportCategory {
LARGE = 'large_airport' LARGE = 'large_airport'
} }
export function airportCategoryToText(category: AirportCategory): string {
switch (category) {
case AirportCategory.SMALL:
return 'Small';
case AirportCategory.MEDIUM:
return 'Medium';
case AirportCategory.LARGE:
return 'Large';
}
}
export enum AirportOrderField { export enum AirportOrderField {
ICAO = 'icao', ICAO = 'icao',
NAME = 'name', NAME = 'name',

View File

@@ -1,6 +1,7 @@
import { getAirports, importAirports, removeAirport } from "@/api/airport"; import { getAirports, importAirports, removeAirport } from "@/api/airport";
import { Airport } from "@/api/airport.types"; import { Airport, AirportCategory, AirportOrderField, airportCategoryToText } from "@/api/airport.types";
import { Text, Button, Card, Group, Pagination, ScrollArea, Table, TextInput, rem } from "@mantine/core"; import { Text, Button, Card, Group, Pagination, ScrollArea, Table, TextInput, rem, UnstyledButton, Center } from "@mantine/core";
import { HiChevronUp, HiChevronDown, HiSelector } from "react-icons/hi";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { CiSearch } from "react-icons/ci"; import { CiSearch } from "react-icons/ci";
@@ -31,15 +32,12 @@ export default function AirportTablePanel({ setAirport }: { setAirport: (airport
const rows = airports.map((airport) => ( const rows = airports.map((airport) => (
<Table.Tr <Table.Tr
key={airport.icao} key={airport.icao}
onClick={() => { onClick={() => setAirport(airport)}
console.log('here');
setAirport(airport);
}}
style={{ cursor: 'pointer' }} style={{ cursor: 'pointer' }}
> >
<Table.Td>{airport.icao}</Table.Td> <Table.Td>{airport.icao}</Table.Td>
<Table.Td>{airport.full_name}</Table.Td> <Table.Td>{airport.full_name}</Table.Td>
<Table.Td>{airport.category}</Table.Td> <Table.Td>{airportCategoryToText(airport.category)}</Table.Td>
<Table.Td>{airport.continent}</Table.Td> <Table.Td>{airport.continent}</Table.Td>
<Table.Td>{airport.iso_country}</Table.Td> <Table.Td>{airport.iso_country}</Table.Td>
<Table.Td>{airport.iso_region}</Table.Td> <Table.Td>{airport.iso_region}</Table.Td>
@@ -61,7 +59,7 @@ export default function AirportTablePanel({ setAirport }: { setAirport: (airport
onChange={handleSearchChange} onChange={handleSearchChange}
/> />
<Table.ScrollContainer minWidth={500} h={500}> <Table.ScrollContainer minWidth={500} h={500}>
<Table highlightOnHover> <Table highlightOnHover stickyHeader>
<Table.Thead> <Table.Thead>
<Table.Tr> <Table.Tr>
<Table.Th>ICAO</Table.Th> <Table.Th>ICAO</Table.Th>
@@ -114,4 +112,22 @@ function PanelButton({ children, color = 'blue', onClick }: {children: any, colo
> >
{children} {children}
</Button> </Button>
} }
function Th({ children, asc, sorted, onSort }: { children: any, asc: boolean, sorted: boolean, onSort: () => void }) {
const Icon = sorted ? (asc ? HiChevronUp : HiChevronDown) : HiSelector;
return (
<Table.Th>
<UnstyledButton onClick={onSort}>
<Group justify="space-between">
<Text fw={500} fz="sm">
{children}
</Text>
<Center>
<Icon style={{ width: rem(16), height: rem(16) }} />
</Center>
</Group>
</UnstyledButton>
</Table.Th>
);
}