Location edition

This commit is contained in:
vjrj 2018-07-05 12:50:08 +02:00
parent e55edce3d4
commit 87718b7ad5
15 changed files with 138 additions and 75 deletions

View file

@ -41,15 +41,16 @@ void fetchYourLocationsMiddleware(
// FXIME save lat/lon
} else {
// No subscribed (only local)
store.dispatch(new UpdateYourLocationAction(action.loc));
persistYourLocations(store.state.yourLocations);
}
}
if (action is AddYourLocationAction) {
if (action.loc.subscribed) {
subscribeViaApi(store, action.loc,
(sub) => store.dispatch(new AddedYourLocationAction(sub)));
(sub) {
store.dispatch(new AddedYourLocationAction(sub));
persistYourLocations(store.state.yourLocations);
});
} else {
// No subscribed (only local)
store.dispatch(new AddedYourLocationAction(action.loc));
@ -73,7 +74,6 @@ void fetchYourLocationsMiddleware(
.getYourLocationFireStats(store.state, action.loc)
.then((result) => store.dispatch(result));
}
if (action is UpdateYourLocationAction) {
if (action.loc.subscribed)
Debounce.seconds(
@ -84,6 +84,8 @@ void fetchYourLocationsMiddleware(
else {
// FIXME do something?
}
store.dispatch(new UpdatedYourLocationAction(action.loc));
persistYourLocations(store.state.yourLocations);
}
if (action is SubscribeConfirmAction) {

View file

@ -1,6 +1,5 @@
import 'package:bson_objectid/bson_objectid.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:meta/meta.dart';
abstract class YourLocationActions {}
@ -34,6 +33,12 @@ class UpdateYourLocationAction extends YourLocationActions {
UpdateYourLocationAction(this.loc);
}
class UpdatedYourLocationAction extends YourLocationActions {
YourLocation loc;
UpdatedYourLocationAction(this.loc);
}
class ToggleSubscriptionAction extends YourLocationActions {
YourLocation loc;

View file

@ -8,8 +8,8 @@ final yourLocationsReducer = combineReducers<List<YourLocation>>([
_addedYourLocation),
new TypedReducer<List<YourLocation>, DeletedYourLocationAction>(
_deletedYourLocation),
new TypedReducer<List<YourLocation>, UpdateYourLocationAction>(
_updateYourLocation),
new TypedReducer<List<YourLocation>, UpdatedYourLocationAction>(
_updatedYourLocation),
new TypedReducer<List<YourLocation>, ToggledSubscriptionAction>(
_toggledSubscriptionAction)
]);
@ -26,8 +26,8 @@ List<YourLocation> _deletedYourLocation(
.toList();
}
List<YourLocation> _updateYourLocation(
List<YourLocation> yourLocations, UpdateYourLocationAction action) {
List<YourLocation> _updatedYourLocation(
List<YourLocation> yourLocations, UpdatedYourLocationAction action) {
return yourLocations
.map((yourLocation) =>
yourLocation.id == action.loc.id ? action.loc : yourLocation)