Fetch fire data on new locations

This commit is contained in:
Vicente J. Ruiz Jurado 2018-08-17 06:49:44 +02:00
parent d40859c5d8
commit 46026917c7

View file

@ -58,6 +58,7 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
store.dispatch(new AddedYourLocationAction(action.loc));
persistYourLocations(store.state.yourLocations);
}
getFiresStatsInLocation(store, action.loc);
}
if (action is DeleteYourLocationAction) {
@ -87,13 +88,7 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
}
if (action is ShowYourLocationMapAction) {
api
.getFiresInLocation(
state: store.state,
lat: action.loc.lat,
lon: action.loc.lon,
distance: action.loc.distance)
.then((result) => store.dispatch(result));
getFiresStatsInLocation(store, action.loc);
}
if (action is ShowFireNotificationMapAction) {
@ -111,9 +106,6 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
lon: action.loc.lon,
distance: action.loc.distance)
.then((result) => store.dispatch(result)));
else {
// FIXME do something?
}
store.dispatch(new UpdatedYourLocationAction(action.loc));
persistYourLocations(store.state.yourLocations);
}
@ -211,18 +203,21 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
}
if (action is FetchMonitoredAreasAction) {
api.getMonitoredAreas(state: store.state).then((result) { // store.dispatch()
store.dispatch(
new FetchMonitoredAreasSucceededAction(result));
api.getMonitoredAreas(state: store.state).then((result) {
// store.dispatch()
store.dispatch(new FetchMonitoredAreasSucceededAction(result));
});
}
if (action is MarkFireAsFalsePositiveAction) {
api.markFalsePositive(store.state, store.state.user.token, action.notif.sealed, action.type).then((result) {
api
.markFalsePositive(store.state, store.state.user.token,
action.notif.sealed, action.type)
.then((result) {
if (result) {
// Not necessary
// store.dispatch(new UpdatedFireNotificationAction(action.notif));
getFiresStatsInFire(store, action.notif);
store.dispatch(new UpdatedFireNotificationAction(action.notif));
}
});
}
@ -231,6 +226,20 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
next(action);
}
void getFiresStatsInLocation(Store<AppState> store, YourLocation loc) {
api
.getFiresInLocation(
state: store.state,
lat: loc.lat,
lon: loc.lon,
distance: loc.distance)
.then((result) {
store.dispatch(result);
loc.currentNumFires = result.numFires;
store.dispatch(new UpdateYourLocationAction(loc));
});
}
void getFiresStatsInFire(Store<AppState> store, FireNotification notif) {
api
.getFiresInLocation(