Added Monitorized Areas

This commit is contained in:
Vicente J. Ruiz Jurado 2018-08-06 10:34:32 +02:00
parent 864ee28584
commit e50ff5179b
16 changed files with 223 additions and 19 deletions

View file

@ -2,6 +2,8 @@ import 'package:fires_flutter/models/yourLocation.dart';
import 'package:fires_flutter/models/fireNotification.dart';
import 'dart:async';
import 'package:connectivity/connectivity.dart';
import 'package:flutter_map/flutter_map.dart';
abstract class AppActions {}
class FetchYourLocationsAction extends AppActions {
@ -20,6 +22,8 @@ class FetchYourLocationsSucceededAction extends AppActions {
class FetchFireNotificationsAction extends AppActions {}
class FetchMonitoredAreasAction extends AppActions {}
class FetchYourLocationsFailedAction extends AppActions {
final Exception error;
@ -55,4 +59,10 @@ class OnConnectivityChanged extends AppActions {
final ConnectivityResult connectivityResult;
OnConnectivityChanged(this.connectivityResult);
}
}
class FetchMonitoredAreasSucceededAction extends AppActions {
final List<Polyline> monitoredAreas;
FetchMonitoredAreasSucceededAction(this.monitoredAreas);
}

View file

@ -9,6 +9,9 @@ AppState appReducer(AppState state, action) {
return state.copyWith(fireNotifications: action.fetchedFireNotifications,
fireNotificationsUnread: action.unreadCount);
}
if (action is FetchMonitoredAreasSucceededAction) {
return state.copyWith(monitoredAreas: action.monitoredAreas);
}
if (action is AddedFireNotificationAction)
return state.copyWith(
fireNotificationsUnread: state.fireNotificationsUnread + 1);

View file

@ -214,6 +214,13 @@ 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));
});
}
// Make sure our actions continue on to the reducer.
next(action);
}
@ -243,5 +250,6 @@ void createUser(store, lang, token) {
store.dispatch(new OnUserCreatedAction(userId));
store.dispatch(new FetchYourLocationsAction());
store.dispatch(new FetchFireNotificationsAction());
store.dispatch(new FetchMonitoredAreasAction());
});
}

View file

@ -21,6 +21,7 @@ AppState appStateReducer(AppState prevState, action) {
isLoaded: loadedReducer(state.isLoaded, action),
error: errorReducer(state.error, action),
fireMapState: fireMapReducer(state.fireMapState, action),
monitoredAreas: state.monitoredAreas,
firesApiKey: state.firesApiKey,
firesApiUrl: state.firesApiUrl,
serverUrl: state.serverUrl,