Add Airline
This commit is contained in:
@@ -7,6 +7,7 @@ const SET_AIRPORTS = 'SET_AIRPORTS';
|
||||
const SET_UNFILTERED_AIRPORTS = 'SET_UNFILTERED_AIRPORTS';
|
||||
const RESET_AIRPORTS = 'RESET_AIRPORTS';
|
||||
const SET_CURRENT_AIRPORT = 'SET_CURRENT_AIRPORT';
|
||||
const UPDATE_CURRENT_AIRPORT = 'UPDATE_CURRENT_AIRPORT';
|
||||
|
||||
const state = {
|
||||
airports: [], unfilteredairports:[], currentAirport: {}
|
||||
@@ -21,6 +22,10 @@ const mutations = {
|
||||
});
|
||||
Vue.set(state, 'airports', state.airports.concat(airports));
|
||||
},
|
||||
'UPDATE_CURRENT_AIRPORT' (state, airport) {
|
||||
Vue.set(state, 'currentAirport', airport.properties);
|
||||
idb.saveAirport(airport);
|
||||
},
|
||||
SET_AIRPORTS (state, airports) {
|
||||
Vue.set(state, 'airports', airports);
|
||||
},
|
||||
@@ -51,6 +56,23 @@ const actions = {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
async addAirline(context, airlineCode) {
|
||||
try {
|
||||
airlineCode = airlineCode.toUpperCase()
|
||||
let airports = await idb.getAirports();
|
||||
let searchRegex = new RegExp(this.state.Airports.currentAirport.icao, 'i');
|
||||
let airport = airports
|
||||
.filter(point => typeof point.geometry.coordinates !== "undefined" )
|
||||
.filter(a => searchRegex.test(a.properties.icao));
|
||||
if (airport[0] !== undefined && !airport[0].properties.airlines.includes(airlineCode)) {
|
||||
airport[0].properties.airlines.push(airlineCode);
|
||||
airport[0].properties.airlines.sort();
|
||||
}
|
||||
context.commit(UPDATE_CURRENT_AIRPORT, airport[0]);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
async setCurrentAirport(context, icao) {
|
||||
try {
|
||||
let airports = await idb.getAirports();
|
||||
|
||||
Reference in New Issue
Block a user