Export button functionality

This commit is contained in:
2024-01-05 20:14:42 -05:00
parent 7ed5e5a673
commit 9f6466c171
3 changed files with 23 additions and 4 deletions

View File

@@ -62,7 +62,7 @@ export async function createAirport({ airport }: { airport: Airport }): Promise<
}
export async function updateAirport({ airport }: { airport: Airport }): Promise<any> {
const response = await putRequest(`airports`, airport);
const response = await putRequest(`airports/${airport.icao}`, airport);
return response?.json() || { data: undefined };
}

View File

@@ -112,7 +112,23 @@ export default function AirportTablePanel({ setShowModal, setAirport }: { setSho
</Space>
<Space mr={'sm'}>
<PanelButton color={'blue'} onClick={async () => {
const airports = [];
let page = 1;
let totalPages = 1;
do {
const response = await getAirports({ limit: 1000, page });
airports.push(...response.data);
totalPages = response.meta.pages;
page++;
} while (page <= totalPages);
if (airports && airports.length > 0) {
const element = document.createElement("a");
const file = new Blob([JSON.stringify(airports)], {type: 'text/plain'});
element.href = URL.createObjectURL(file);
element.download = "airports.json";
document.body.appendChild(element); // Required for this to work in FireFox
element.click();
}
}}>
Export
</PanelButton>

View File

@@ -56,7 +56,8 @@ export default function MapTiles() {
limit: zoom < 4 ? 200 : 100,
page: 1
});
const { data: metars } = await getMetars(airportData.map((a) => a.icao));
const airports = airportData.filter((airport) => airport.has_metar);
const { data: metars } = await getMetars(airports.map((a) => a.icao));
metars.forEach((metar) => {
airportData.forEach((airport) => {
if (metar.station_id == airport.icao) {
@@ -69,7 +70,9 @@ export default function MapTiles() {
function metarIcon(airport: Airport) {
let iconUrl = '/icons/unkn.svg';
if (airport.latest_metar?.flight_category == 'VFR') {
if (!airport.has_metar) {
iconUrl = '/icons/nometar.svg';
} else if (airport.latest_metar?.flight_category == 'VFR') {
iconUrl = '/icons/vfr.svg';
} else if (airport.latest_metar?.flight_category == 'MVFR') {
iconUrl = '/icons/mvfr.svg';