Export button functionality
This commit is contained in:
@@ -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>
|
||||
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user