bukopin-redemption-client-r.../src/common/stores/airports.js
Rifqy Zacky Ariadhy 1a000700e6 Initial commit
2019-01-02 18:39:53 +07:00

54 lines
1.1 KiB
JavaScript

import {observable, action, computed} from 'mobx';
export default class Airports {
@observable lists = [];
@observable searchResults = [];
@observable isLoading = false;
@observable selectedDepartureAirport = "";
@observable selectedArrivalAirport = "";
@computed
get listForSearch() {
return this.lists;
}
constructor(context) {
this.http = context.http;
this.context = context;
}
@action
setSelectedAirport(item, type) {
console.log(item, type)
if (type == 'departure') {
this.selectedDepartureAirport = item;
} else {
this.selectedArrivalAirport = item;
}
}
@action
getAllAirports() {
this.isLoading = true;
return this.http.get(`master/airports`).then(res => {
this.lists = res;
this.isLoading = false;
});
}
@action
searchAirports(name) {
this.isLoading = true;
return this.http.get(`master/airports?search=${name}`)
.then(res => {
this.isLoading = false;
this.lists = res;
})
.catch(err => {
this.isLoading = false;
throw err;
});
}
}