Created
March 18, 2015 11:19
-
-
Save arnarthor/11937797ecb5c4ebc99f to your computer and use it in GitHub Desktop.
addFlight
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
addFlight(flight) { | |
// If we are home | |
if(flight.stateData === 'homeDest'){ | |
return; | |
} | |
let flights = _.clone(this.state.flights); | |
let lastFlight; | |
// If we got a succesfull new flight | |
if (flights.length> 0) { | |
lastFlight = _.last(flights); | |
let currentArrival = moment(lastFlight.departure); | |
let nextArrival = moment(flight.departure); | |
lastFlight.daysStaying = currentArrival.from(nextArrival); | |
flights = _.initial(flights).concat(lastFlight); | |
} | |
// Update the flights global array | |
this.setState({flights: flights.concat(flight)}); | |
//Fetch another flight | |
let travelingData = { | |
departure: { | |
airportName: flight.arrivalCountry.airportName, | |
country: flight.arrivalCountry.countryCode, | |
airportCode: flight.destAirport, | |
from: moment(flight.departure).add(flight.stopDuration.lowBound,'days').format('YYYY-MM-DD'), | |
to: moment(flight.departure).add(flight.stopDuration.highBound, 'days').format('YYYY-MM-DD'), | |
lat: flight.arrivalCountry.lat, | |
lon: flight.arrivalCountry.lon, | |
}, | |
flights: this.state.flights, | |
startingPoint: this.state.selectedAirport, | |
stopDuration:flight.stopDuration, | |
endDate:flight.endDate, | |
stateData:'newFlight' | |
}; | |
this.socket.emit('request-flight', travelingData); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment