updates
This commit is contained in:
@@ -1,13 +1,13 @@
|
||||
import { Airport, AirportOrderField, Bounds, GetAirportResponse, GetAirportsResponse } from './airport.types';
|
||||
import { Airport, AirportOrderField, Bounds, GetAirportsResponse } from './airport.types';
|
||||
import { getRequest, deleteRequest, postRequest, putRequest } from '.';
|
||||
|
||||
interface GetAirportProps {
|
||||
icao: string;
|
||||
}
|
||||
|
||||
export async function getAirport({ icao }: GetAirportProps): Promise<GetAirportResponse> {
|
||||
export async function getAirport({ icao }: GetAirportProps): Promise<Airport> {
|
||||
const response = await getRequest(`airports/${icao}`);
|
||||
return response?.json() || { data: undefined };
|
||||
return response?.json() || {};
|
||||
}
|
||||
|
||||
interface GetAirportsProps {
|
||||
|
||||
@@ -86,11 +86,6 @@ export interface Frequency {
|
||||
frequency_mhz: number;
|
||||
}
|
||||
|
||||
export interface GetAirportResponse {
|
||||
data: Airport;
|
||||
meta: Metadata;
|
||||
}
|
||||
|
||||
export interface GetAirportsResponse {
|
||||
data: Airport[];
|
||||
meta: Metadata;
|
||||
|
||||
@@ -75,6 +75,5 @@ export async function deleteRequest(endpoint: string): Promise<Response> {
|
||||
export interface Metadata {
|
||||
limit: number;
|
||||
page: number;
|
||||
pages: number;
|
||||
total: number;
|
||||
}
|
||||
|
||||
@@ -1,15 +1,11 @@
|
||||
import { Metar } from './metar.types';
|
||||
import { getRequest } from '.';
|
||||
|
||||
interface GetMetarsResponse {
|
||||
data: Metar[];
|
||||
}
|
||||
|
||||
export async function getMetars(icaos: string[]): Promise<GetMetarsResponse> {
|
||||
export async function getMetars(icaos: string[]): Promise<Metar[]> {
|
||||
if (icaos.length == 0) {
|
||||
return { data: [] };
|
||||
return [];
|
||||
}
|
||||
const stationICAOs: string = icaos.map((icao) => icao).join(',');
|
||||
const response = await getRequest(`metars`, { icaos: stationICAOs });
|
||||
return response?.json() || { data: [] };
|
||||
return response?.json() || [];
|
||||
}
|
||||
|
||||
@@ -13,9 +13,9 @@ export default function Page({ params }: { params: { icao: string } }) {
|
||||
|
||||
useEffect(() => {
|
||||
async function loadAirport() {
|
||||
const { data: airportData } = await getAirport({ icao: params.icao });
|
||||
const airportData = await getAirport({ icao: params.icao });
|
||||
setAirport(airportData);
|
||||
const { data: metarData } = await getMetars([airportData.icao]);
|
||||
const metarData = await getMetars([airportData.icao]);
|
||||
if (metarData.length > 0) {
|
||||
setMetar(metarData[0]);
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ export default function MapTiles() {
|
||||
page: 1
|
||||
});
|
||||
const airports = airportData.filter((airport) => airport.has_metar);
|
||||
const { data: metars } = await getMetars(airports.map((a) => a.icao));
|
||||
const metars = await getMetars(airports.map((a) => a.icao));
|
||||
metars.forEach((metar) => {
|
||||
airportData.forEach((airport) => {
|
||||
if (metar.station_id == airport.icao) {
|
||||
|
||||
Reference in New Issue
Block a user