Better fire stats. False positives mark api part
This commit is contained in:
parent
e9c6c3fc55
commit
cb02156ae1
10 changed files with 174 additions and 75 deletions
|
|
@ -97,13 +97,7 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
|
|||
}
|
||||
|
||||
if (action is ShowFireNotificationMapAction) {
|
||||
api
|
||||
.getFiresInLocation(
|
||||
state: store.state,
|
||||
lat: action.notif.lat,
|
||||
lon: action.notif.lon,
|
||||
distance: 1) // FalsePositive/server/publications.js
|
||||
.then((result) => store.dispatch(result));
|
||||
getFiresStatsInFire(store, action.notif);
|
||||
}
|
||||
|
||||
if (action is UpdateYourLocationAction) {
|
||||
|
|
@ -221,10 +215,30 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
|
|||
});
|
||||
}
|
||||
|
||||
if (action is MarkFireAsFalsePositiveAction) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// Make sure our actions continue on to the reducer.
|
||||
next(action);
|
||||
}
|
||||
|
||||
void getFiresStatsInFire(Store<AppState> store, FireNotification notif) {
|
||||
api
|
||||
.getFiresInLocation(
|
||||
state: store.state,
|
||||
lat: notif.lat,
|
||||
lon: notif.lon,
|
||||
distance: 1) // FalsePositive/server/publications.js
|
||||
.then((result) => store.dispatch(result));
|
||||
}
|
||||
|
||||
void unsubsViaApi(Store<AppState> store, ObjectId id, onUnsubs) {
|
||||
api.unsubscribe(store.state, id.toHexString()).then((res) {
|
||||
onUnsubs();
|
||||
|
|
|
|||
|
|
@ -12,13 +12,13 @@ class UpdateYourLocationMapAction extends FiresMapActions {
|
|||
);
|
||||
}
|
||||
|
||||
class UpdateYourLocationMapStatsAction extends FiresMapActions {
|
||||
class UpdateFireMapStatsAction extends FiresMapActions {
|
||||
int numFires;
|
||||
List<dynamic> fires = [];
|
||||
List<dynamic> falsePos = [];
|
||||
List<dynamic> industries = [];
|
||||
|
||||
UpdateYourLocationMapStatsAction(
|
||||
UpdateFireMapStatsAction(
|
||||
{@required this.numFires,
|
||||
@required this.fires,
|
||||
@required this.falsePos,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ final fireMapReducer = combineReducers<FireMapState>([
|
|||
_showYourLocationMap),
|
||||
new TypedReducer<FireMapState, ShowFireNotificationMapAction>(
|
||||
_showFireNotificationMap),
|
||||
new TypedReducer<FireMapState, UpdateYourLocationMapStatsAction>(
|
||||
new TypedReducer<FireMapState, UpdateFireMapStatsAction>(
|
||||
_updateYourLocationMapStats),
|
||||
new TypedReducer<FireMapState, SubscribeAction>(_subscribeYourLocationMap),
|
||||
new TypedReducer<FireMapState, SubscribeConfirmAction>(
|
||||
|
|
@ -27,7 +27,7 @@ final fireMapReducer = combineReducers<FireMapState>([
|
|||
]);
|
||||
|
||||
FireMapState _updateYourLocationMapStats(
|
||||
FireMapState state, UpdateYourLocationMapStatsAction action) {
|
||||
FireMapState state, UpdateFireMapStatsAction action) {
|
||||
return state.copyWith(
|
||||
numFires: action.numFires,
|
||||
fires: action.fires,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
import '../models/falsePositiveTypes.dart';
|
||||
|
||||
abstract class FireNotificationActions {}
|
||||
|
||||
|
|
@ -45,3 +46,16 @@ class ReadedFireNotificationAction extends FireNotificationActions {
|
|||
|
||||
ReadedFireNotificationAction(this.notif);
|
||||
}
|
||||
|
||||
class MarkFireAsFalsePositiveAction extends FireNotificationActions {
|
||||
final FireNotification notif;
|
||||
final FalsePositiveType type;
|
||||
|
||||
MarkFireAsFalsePositiveAction(this.notif, this.type);
|
||||
}
|
||||
|
||||
class UpdatedFireNotificationAction extends FireNotificationActions {
|
||||
final FireNotification notif;
|
||||
|
||||
UpdatedFireNotificationAction(this.notif);
|
||||
}
|
||||
|
|
@ -1,17 +1,19 @@
|
|||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
|
||||
import 'actions.dart';
|
||||
import 'package:fires_flutter/models/fireNotification.dart';
|
||||
|
||||
final fireNotificationReducer = combineReducers<List<FireNotification>>([
|
||||
new TypedReducer<List<FireNotification>, AddedFireNotificationAction>(
|
||||
_addedFireNotification),
|
||||
new TypedReducer<List<FireNotification>, DeletedFireNotificationAction>(
|
||||
_deletedFireNotification),
|
||||
_deletedFireNotification),
|
||||
new TypedReducer<List<FireNotification>, UpdatedFireNotificationAction>(
|
||||
_updatedFireNotification),
|
||||
new TypedReducer<List<FireNotification>, DeletedAllFireNotificationAction>(
|
||||
_deletedAllFireNotifications),
|
||||
_deletedAllFireNotifications),
|
||||
new TypedReducer<List<FireNotification>, ReadedFireNotificationAction>(
|
||||
_readedFireNotification)
|
||||
_readedFireNotification)
|
||||
]);
|
||||
|
||||
List<FireNotification> _addedFireNotification(
|
||||
|
|
@ -20,10 +22,18 @@ List<FireNotification> _addedFireNotification(
|
|||
}
|
||||
|
||||
List<FireNotification> _deletedFireNotification(
|
||||
List<FireNotification> notifications, DeletedFireNotificationAction action) {
|
||||
List<FireNotification> notifications,
|
||||
DeletedFireNotificationAction action) {
|
||||
return new List.from(notifications)..remove(action.notif);
|
||||
}
|
||||
|
||||
List<FireNotification> _updatedFireNotification(
|
||||
List<FireNotification> notifications, UpdatedFireNotificationAction action) {
|
||||
return notifications
|
||||
.map((notif) => notif.id == action.notif.id ? action.notif : notif)
|
||||
.toList();
|
||||
}
|
||||
|
||||
List<FireNotification> _readedFireNotification(
|
||||
List<FireNotification> notifications, ReadedFireNotificationAction action) {
|
||||
return notifications
|
||||
|
|
@ -33,6 +43,7 @@ List<FireNotification> _readedFireNotification(
|
|||
}
|
||||
|
||||
List<FireNotification> _deletedAllFireNotifications(
|
||||
List<FireNotification> notifications, DeletedAllFireNotificationAction action) {
|
||||
List<FireNotification> notifications,
|
||||
DeletedAllFireNotificationAction action) {
|
||||
return new List<FireNotification>();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue