Single ICAO search
This commit is contained in:
parent
ae680eb994
commit
9eb92fb13d
@ -128,10 +128,20 @@
|
||||
searched: function () {
|
||||
console.log(this.searchterm)
|
||||
let searchRegex = new RegExp(this.searchterm, 'i')
|
||||
return this.$store.state.Airports.airports
|
||||
let result = this.$store.state.Airports.airports
|
||||
.filter(point => point.geometry !== undefined)
|
||||
.filter(point => point.geometry.coordinates !== undefined)
|
||||
.filter(a => a.properties !== undefined)
|
||||
.filter(a => searchRegex.test(a.properties.icao) || searchRegex.test(a.properties.name))
|
||||
// .map(a => console.log(a.properties))
|
||||
.map(a => ({ icao: a.properties.icao, name: a.properties.name }))
|
||||
if (result !== undefined &&
|
||||
result.length === 0 &&
|
||||
this.searchterm !== undefined &&
|
||||
this.searchterm.length >= 3) {
|
||||
this.$store.dispatch('getAirport', this.searchterm)
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ const state = {
|
||||
const mutations = {
|
||||
'DELETE_INDEXED_DB' () { },
|
||||
ADD_AIRPORT (state, airports) {
|
||||
state.airports.push(airports);
|
||||
Vue.set(state, 'airports', state.airports.concat(airports));
|
||||
},
|
||||
SET_AIRPORTS (state, airports) {
|
||||
Vue.set(state, 'airports', airports);
|
||||
@ -43,6 +43,18 @@ const actions = {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
async getAirport(context, icao) {
|
||||
try {
|
||||
let airports = await idb.getAirports();
|
||||
let searchRegex = new RegExp(icao, 'i');
|
||||
let airport = airports
|
||||
.filter(point => typeof point.geometry.coordinates !== "undefined" )
|
||||
.filter(a => searchRegex.test(a.properties.icao));
|
||||
context.commit(ADD_AIRPORT, airport);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
},
|
||||
async getAirportsUnfiltered(context) {
|
||||
try {
|
||||
context.commit(RESET_AIRPORTS);
|
||||
|
Loading…
Reference in New Issue
Block a user