Export button functionality
This commit is contained in:
@@ -62,7 +62,7 @@ export async function createAirport({ airport }: { airport: Airport }): Promise<
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function updateAirport({ airport }: { airport: Airport }): Promise<any> {
|
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 };
|
return response?.json() || { data: undefined };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -112,7 +112,23 @@ export default function AirportTablePanel({ setShowModal, setAirport }: { setSho
|
|||||||
</Space>
|
</Space>
|
||||||
<Space mr={'sm'}>
|
<Space mr={'sm'}>
|
||||||
<PanelButton color={'blue'} onClick={async () => {
|
<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
|
Export
|
||||||
</PanelButton>
|
</PanelButton>
|
||||||
|
|||||||
@@ -56,7 +56,8 @@ export default function MapTiles() {
|
|||||||
limit: zoom < 4 ? 200 : 100,
|
limit: zoom < 4 ? 200 : 100,
|
||||||
page: 1
|
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) => {
|
metars.forEach((metar) => {
|
||||||
airportData.forEach((airport) => {
|
airportData.forEach((airport) => {
|
||||||
if (metar.station_id == airport.icao) {
|
if (metar.station_id == airport.icao) {
|
||||||
@@ -69,7 +70,9 @@ export default function MapTiles() {
|
|||||||
|
|
||||||
function metarIcon(airport: Airport) {
|
function metarIcon(airport: Airport) {
|
||||||
let iconUrl = '/icons/unkn.svg';
|
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';
|
iconUrl = '/icons/vfr.svg';
|
||||||
} else if (airport.latest_metar?.flight_category == 'MVFR') {
|
} else if (airport.latest_metar?.flight_category == 'MVFR') {
|
||||||
iconUrl = '/icons/mvfr.svg';
|
iconUrl = '/icons/mvfr.svg';
|
||||||
|
|||||||
Reference in New Issue
Block a user