From e8b2a6d0c08f9dba6dfc1d7797c138050c4cc217 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Wed, 15 Aug 2018 05:42:22 +0200 Subject: [PATCH 1/9] Messages dispatch when store is loaded --- lib/homePage.dart | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/homePage.dart b/lib/homePage.dart index 5e1aaf1..f4c2544 100644 --- a/lib/homePage.dart +++ b/lib/homePage.dart @@ -84,14 +84,14 @@ class _HomePageState extends State { super.initState(); _firebaseMessaging.configure(onMessage: (Map message) { debugPrint("onMessage in fireApp (isLoaded: ${store.state.isLoaded}): $message"); - _showItemDialog(message, _notifForMessage(message)); + _showItemDialog(message, _notifForMessage(message, store.state.isLoaded)); }, onLaunch: (Map message) { debugPrint("onLaunch (isLoaded: ${store.state.isLoaded}): $message"); - _notifForMessage(message); + _notifForMessage(message, store.state.isLoaded); _navigateToItemDetail(message); }, onResume: (Map message) { debugPrint("onResume (isLoaded: ${store.state.isLoaded}): $message"); - _notifForMessage(message); + _notifForMessage(message, store.state.isLoaded); _navigateToItemDetail(message); }); _firebaseMessaging.requestNotificationPermissions( @@ -282,7 +282,7 @@ class _HomePageState extends State { // https://pub.dartlang.org/packages/firebase_messaging#-example-tab- final FirebaseMessaging _firebaseMessaging = new FirebaseMessaging(); - FireNotification _notifForMessage(Map message) { + FireNotification _notifForMessage(Map message, bool isLoaded) { FireNotification notif; try { notif = new FireNotification( @@ -299,7 +299,12 @@ class _HomePageState extends State { debugPrint(e.toString()); } if (notif != null) - newNotifications.add(notif); + // if our store is loaded, we just dispatch the notification, if not, we wait til is loaded + if (isLoaded) { + store.dispatch(new AddFireNotificationAction(notif)); + } else { + newNotifications.add(notif); + } return notif; } } From d5bb87af276090d21cf23cf79db99066aee539d4 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Wed, 15 Aug 2018 05:56:48 +0200 Subject: [PATCH 2/9] Subs/unsubs optimistic --- lib/activeFires.dart | 3 ++- lib/generated/i18n.dart | 6 ++++++ res/values/strings_en.arb | 4 +++- res/values/strings_es.arb | 4 +++- 4 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/activeFires.dart b/lib/activeFires.dart index 11884ea..adfd456 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -5,7 +5,6 @@ import 'package:fires_flutter/models/yourLocation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_fab_dialer/flutter_fab_dialer.dart'; import 'package:flutter_redux/flutter_redux.dart'; -import 'package:flutter_spinkit/flutter_spinkit.dart'; import 'package:redux/src/store.dart'; import 'colors.dart'; @@ -95,6 +94,8 @@ class _ActiveFiresPageState extends State { onPressed: () { loc.subscribed = !loc.subscribed; onToggle(loc); + setState(() {}); + showSnackMsg(loc.subscribed? S.of(context).subscribedToFires: S.of(context).unsubscribedToFires); }), title: new Text(loc.description, style: new TextStyle(fontSize: 16.0)), subtitle: loc.currentNumFires == YourLocation.withoutStats diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart index 9555e5a..878899b 100644 --- a/lib/generated/i18n.dart +++ b/lib/generated/i18n.dart @@ -75,6 +75,7 @@ class S implements WidgetsLocalizations { String get privacyPolicy => "Privacy Policy"; String get shareAppBtn => "Share our app"; String get starAppBtn => "Rate our app"; + String get subscribedToFires => "Subscribed to fires notifications"; String get supportPageDescription => "You can support this initiative, spreading the word, helping us to develop our software, translating this app to your language, suggesting other public data sources of fires to use, etc."; String get supportThisInitiative => "Support this initiative"; String get thanksForParticipating => "Thanks for participating"; @@ -85,6 +86,7 @@ class S implements WidgetsLocalizations { String get tweetAboutAFireTitle => "Tweet about"; String get typeTheNameOfAPlace => "Type the name of a place, region, etc"; String get unsubscribe => "Unsubscribe"; + String get unsubscribedToFires => "Unsubscribed to fires notifications"; String get warningThisIsAVeryLargeArea => "Warning: this is a very large area"; String get youDeletedThisNotification => "You deleted this notification"; String get youDeletedThisPlace => "You deleted this place"; @@ -177,6 +179,8 @@ class es extends S { @override String get aYear => "un año"; @override + String get unsubscribedToFires => "Desuscrito a notificaciones de fuegos"; + @override String get itSeemsNotAtForesFire => "Parece que este fuego no es un fuego forestal."; @override String get UNDO => "DESHACER"; @@ -193,6 +197,8 @@ class es extends S { @override String get NASAAck => "Reconocemos el uso de datos e imágenes de LANCE FIRMS operadas por NASA/GSFC/Earth Science Data and Information System (ESDIS) con fondos proporcionados por NASA/HQ."; @override + String get subscribedToFires => "Suscrito a notificaciones de fuegos"; + @override String get isYourUbicationEnabled => "No podemos saber tu ubicación actual. ¿Están los servicios de ubicación en tu móvil activados?"; @override String get thanksForParticipating => "Gracias por Participar"; diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index eab1be2..94c89eb 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -79,5 +79,7 @@ "mapPrivacy": "In order to preserve the privacy of our users, the reflected data are randomly altered and are only indicative.", "comunesSupportBtn": "Know and support our work", "shareAppBtn": "Share our app", - "starAppBtn": "Rate our app" + "starAppBtn": "Rate our app", + "unsubscribedToFires": "Unsubscribed to fires notifications", + "subscribedToFires": "Subscribed to fires notifications" } \ No newline at end of file diff --git a/res/values/strings_es.arb b/res/values/strings_es.arb index ac01162..04b646e 100644 --- a/res/values/strings_es.arb +++ b/res/values/strings_es.arb @@ -79,5 +79,7 @@ "mapPrivacy": "Para preservar la privacidad de nuestros usuarios/as, los datos reflejados están aleatoriamente alterados y son solo orientativos.", "comunesSupportBtn": "Conoce y apoya nuestro trabajo", "shareAppBtn": "Comparte nuestra app", - "starAppBtn": "Puntúa nuestra app" + "starAppBtn": "Puntúa nuestra app", + "unsubscribedToFires": "Desuscrito a notificaciones de fuegos", + "subscribedToFires": "Suscrito a notificaciones de fuegos" } \ No newline at end of file From 7b33b3fe7044556b8eafdbe81cf4fd76ecf22be6 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Wed, 15 Aug 2018 06:29:44 +0200 Subject: [PATCH 3/9] False positive, only type --- lib/models/firesApi.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/models/firesApi.dart b/lib/models/firesApi.dart index 23df2bb..a689bbc 100644 --- a/lib/models/firesApi.dart +++ b/lib/models/firesApi.dart @@ -192,7 +192,7 @@ class FiresApi { "token": state.firesApiKey, "mobileToken": mobileToken, "sealed": sealed, - "type": type.toString() + "type": type.toString().split('.')[1] }; final String url = '${state.firesApiUrl}mobile/falsepositive'; return await resty.post(url).json(params).go().then((response) { From 81a0d54a569c3baa15cbd9ffc4ce6b881f7cd365 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Wed, 15 Aug 2018 07:03:30 +0200 Subject: [PATCH 4/9] More work with fire alerts --- lib/fireAlert.dart | 27 +++++++++++++++++++++++++-- lib/generated/i18n.dart | 12 ++++++++++++ res/values/strings_en.arb | 6 +++++- res/values/strings_es.arb | 6 +++++- 4 files changed, 47 insertions(+), 4 deletions(-) diff --git a/lib/fireAlert.dart b/lib/fireAlert.dart index 80e78c7..3fd2322 100644 --- a/lib/fireAlert.dart +++ b/lib/fireAlert.dart @@ -33,6 +33,22 @@ class _FireAlertState extends State { ); } + Widget buildNotifyNeighboursButton() { + return new Align( + alignment: const Alignment(0.0, -0.2), + child: new FloatingActionButton( + heroTag: 'neighAction', + child: const Icon(CommunityMaterialIcons.bullhorn), + onPressed: () { + _scaffoldKey.currentState.showSnackBar(new SnackBar( + content: new Text(S.of(context).inDevelopment), + )); + }, + ), + ); + } + + Widget buildTweetButton() { return new Align( alignment: const Alignment(0.0, -0.2), @@ -46,7 +62,7 @@ class _FireAlertState extends State { String where = yourLocation.description.replaceAll(' ', '').split(',')[0]; print(where); - Share.share('#IF${where} FIXME'); + Share.share(S.of(context).tweetAboutSelf(yourLocation.description, '#IF${where}')); }).catchError((onError) { _scaffoldKey.currentState.showSnackBar(new SnackBar( content: new Text( @@ -65,12 +81,19 @@ class _FireAlertState extends State { List fireSteps = listWithoutNulls([ new CustomStep( title: new Text(S.of(context).callEmergencyServicesTitle), - // subtitle: content: new Column(children: [ new Text(S.of(context).callEmergencyServicesDescription), new SizedBox(height: 20.0), buildCallButton() ])), + new CustomStep( + title: new Text(S.of(context).notifyNeighbours), + // state: CustomStepState.disabled, + content: new Column(children: [ + new Text(S.of(context).notifyNeighboursDescription), + new SizedBox(height: 20.0), + buildNotifyNeighboursButton() + ])), // TODO conditional: this only in Spain new CustomStep( title: new Text(S.of(context).tweetAboutAFireTitle), diff --git a/lib/generated/i18n.dart b/lib/generated/i18n.dart index 878899b..b43f6e0 100644 --- a/lib/generated/i18n.dart +++ b/lib/generated/i18n.dart @@ -59,6 +59,7 @@ class S implements WidgetsLocalizations { String get firesInYourPlaces => "Active fires in your places"; String get firesNearPlace => "Fires near other place"; String get getAlertsOfFiresinThatArea => "Get alerts of fires in that area"; + String get inDevelopment => "In development"; String get inGreenMonitoredAreas => "In green, the areas monitored by our users currently"; String get isYourUbicationEnabled => "I cannot get your current location. It's your ubication enabled?"; String get itSeemsAControlledBurning => "It's a controlled burning"; @@ -72,6 +73,8 @@ class S implements WidgetsLocalizations { String get notAWildfire => "Isn't that a forest fire?"; String get notPermsUbication => "We don't have permission to get your location"; String get notifyAFire => "Notify a fire"; + String get notifyNeighbours => "Notify other users"; + String get notifyNeighboursDescription => "Alert other users of the area about the fire"; String get privacyPolicy => "Privacy Policy"; String get shareAppBtn => "Share our app"; String get starAppBtn => "Rate our app"; @@ -103,6 +106,7 @@ class S implements WidgetsLocalizations { String noFiresAroundThisArea(String kmAround) => "There is no fires at $kmAround км around this area"; String somethingAgo(String something) => "$something ago"; String subscribeToValueAroundThisArea(String sliderValue) => "Subscribe to $sliderValue км around this area"; + String tweetAboutSelf(String location, String hash) => "Fire in $location $hash"; String updatedLastCheck(String lastCheck) => "Updated $lastCheck"; } @@ -185,6 +189,10 @@ class es extends S { @override String get UNDO => "DESHACER"; @override + String get notifyNeighbours => "Notifica a otros usuarios/as"; + @override + String get inDevelopment => "En desarrollo"; + @override String get tweetAboutAFireTitle => "Twittea"; @override String get supportPageDescription => "Puedes apoyar esta iniciativa, dando difusión, ayudándonos a desarrollar nuestro software, traduciendo esta aplicación a tu idioma, sugeriendo otras fuentes de datos públicas de fuegos para usar, etc."; @@ -235,6 +243,8 @@ class es extends S { @override String get firesInTheWorld => "Fuegos en el mundo"; @override + String get notifyNeighboursDescription => "Alerta a otros usuarios de la zona sobre el fuego"; + @override String get addSomePlace => "Añade otro lugar"; @override String get confirm => "Confirmar"; @@ -267,6 +277,8 @@ class es extends S { @override String somethingAgo(String something) => "hace $something"; @override + String tweetAboutSelf(String location, String hash) => "Fuego en $location $hash"; + @override String subscribeToValueAroundThisArea(String sliderValue) => "Suscríbete a $sliderValue км a la redonda"; @override String inHours(String value) => "$value horas"; diff --git a/res/values/strings_en.arb b/res/values/strings_en.arb index 94c89eb..9e4e49f 100644 --- a/res/values/strings_en.arb +++ b/res/values/strings_en.arb @@ -53,8 +53,11 @@ "errorFirePlaceDialog": "We couldn't get the location of the fire", "callEmergencyServicesTitle": "Call 112", "callEmergencyServicesDescription": "You should call 112 if you have not already done so to notify the emergency services.", + "notifyNeighbours": "Notify other users", + "notifyNeighboursDescription": "Alert other users of the area about the fire", "tweetAboutAFireTitle": "Tweet about", "tweetAboutAFireDescription": "Additionally if you use twitter you can share additional information with the emergency services, for example, attaching photos to the tweet if you have good visibility of the fire, when you took the photos, exact location, etc. Use #hashtags type #IFMinicipalTerminal for example #IFJumilla (Forest Fire in Jumilla).", + "tweetAboutSelf": "Fire in $location $hash", "supportPageDescription": "You can support this initiative, spreading the word, helping us to develop our software, translating this app to your language, suggesting other public data sources of fires to use, etc.", "fireNotificationsTitleShort": "Notifications", "fireNotificationsTitle": "Fire Notifications", @@ -81,5 +84,6 @@ "shareAppBtn": "Share our app", "starAppBtn": "Rate our app", "unsubscribedToFires": "Unsubscribed to fires notifications", - "subscribedToFires": "Subscribed to fires notifications" + "subscribedToFires": "Subscribed to fires notifications", + "inDevelopment": "In development" } \ No newline at end of file diff --git a/res/values/strings_es.arb b/res/values/strings_es.arb index 04b646e..96e0cb9 100644 --- a/res/values/strings_es.arb +++ b/res/values/strings_es.arb @@ -53,8 +53,11 @@ "errorFirePlaceDialog": "No hemos podido obtener la ubicación del fuego", "callEmergencyServicesTitle": "Llama al 112", "callEmergencyServicesDescription": "Deberías llamar al 112 si no lo has hecho ya para avisar a los servicios de emergencia.", + "notifyNeighbours": "Notifica a otros usuarios/as", + "notifyNeighboursDescription": "Alerta a otros usuarios de la zona sobre el fuego", "tweetAboutAFireTitle": "Twittea", "tweetAboutAFireDescription": "Adicionalmente si usas twitter puedes compartir información adicional con los servicios de emergencia, por ejemplo, adjuntando fotos al tweet si tienes buena visibilidad del fuego, cuando tomaste las fotos, ubicación exacta, etc. Usa #hashtags tipo #IFTerminoMunicipal por ejemplo #IFJumilla (Incendio Forestal en Jumilla).", + "tweetAboutSelf": "Fuego en $location $hash", "supportPageDescription": "Puedes apoyar esta iniciativa, dando difusión, ayudándonos a desarrollar nuestro software, traduciendo esta aplicación a tu idioma, sugeriendo otras fuentes de datos públicas de fuegos para usar, etc.", "fireNotificationsTitle": "Notificaciones de fuegos", "fireNotificationTitle": "Notificación de fuego", @@ -81,5 +84,6 @@ "shareAppBtn": "Comparte nuestra app", "starAppBtn": "Puntúa nuestra app", "unsubscribedToFires": "Desuscrito a notificaciones de fuegos", - "subscribedToFires": "Suscrito a notificaciones de fuegos" + "subscribedToFires": "Suscrito a notificaciones de fuegos", + "inDevelopment": "En desarrollo" } \ No newline at end of file From 2bcdb7e77c75b1fe9cdade84189b2e5347956a56 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Wed, 15 Aug 2018 07:04:20 +0200 Subject: [PATCH 5/9] version 1.8 --- android/app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/android/app/build.gradle b/android/app/build.gradle index ddd7e38..070fb6f 100644 --- a/android/app/build.gradle +++ b/android/app/build.gradle @@ -30,8 +30,8 @@ android { applicationId "org.comunes.fires" minSdkVersion 16 targetSdkVersion 27 - versionCode 7 - versionName "1.7" + versionCode 8 + versionName "1.8" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } From 32f3f065ae3ac1521aa3df3c57fd01b5cbdd568a Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Wed, 15 Aug 2018 10:28:10 +0200 Subject: [PATCH 6/9] Fire stats in active fires after add --- lib/activeFires.dart | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/activeFires.dart b/lib/activeFires.dart index adfd456..04a4641 100644 --- a/lib/activeFires.dart +++ b/lib/activeFires.dart @@ -8,6 +8,7 @@ import 'package:flutter_redux/flutter_redux.dart'; import 'package:redux/src/store.dart'; import 'colors.dart'; +import 'firesSpinner.dart'; import 'generated/i18n.dart'; import 'genericMap.dart'; import 'globalFiresBottomStats.dart'; @@ -16,7 +17,6 @@ import 'mainDrawer.dart'; import 'models/appState.dart'; import 'placesAutocompleteUtils.dart'; import 'redux/actions.dart'; -import 'firesSpinner.dart'; @immutable class _ViewModel { @@ -95,7 +95,9 @@ class _ActiveFiresPageState extends State { loc.subscribed = !loc.subscribed; onToggle(loc); setState(() {}); - showSnackMsg(loc.subscribed? S.of(context).subscribedToFires: S.of(context).unsubscribedToFires); + showSnackMsg(loc.subscribed + ? S.of(context).subscribedToFires + : S.of(context).unsubscribedToFires); }), title: new Text(loc.description, style: new TextStyle(fontSize: 16.0)), subtitle: loc.currentNumFires == YourLocation.withoutStats @@ -103,12 +105,16 @@ class _ActiveFiresPageState extends State { : loc.currentNumFires == 0 ? new Text(S.of(context).noFiresAround) : loc.currentNumFires == 1 - ? new Text(S - .of(context) - .fireAroundThisArea(loc.distance.toString()), style: fireStatsStyle) - : new Text(S.of(context).firesAroundThisArea( - loc.currentNumFires.toString(), - loc.distance.toString()), style: fireStatsStyle), + ? new Text( + S + .of(context) + .fireAroundThisArea(loc.distance.toString()), + style: fireStatsStyle) + : new Text( + S.of(context).firesAroundThisArea( + loc.currentNumFires.toString(), + loc.distance.toString()), + style: fireStatsStyle), onLongPress: () { showSnackMsg(S.of(context).toDeleteThisPlace); }, From 07d28414bec64b730a1071c4d06081fe5d275785 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Wed, 15 Aug 2018 20:45:13 +0200 Subject: [PATCH 7/9] Parse doubles --- lib/genericMap.dart | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/genericMap.dart b/lib/genericMap.dart index 157a48e..018ff9f 100644 --- a/lib/genericMap.dart +++ b/lib/genericMap.dart @@ -388,19 +388,19 @@ class _genericMapState extends State { falsePosList.forEach((falsePos) { var coords = falsePos['geo']['coordinates']; // print('false pos: ${coords}'); - var loc = LatLng(coords[1], coords[0]); + var loc = LatLng(double.parse(coords[1]), double.parse(coords[0])); markers.add(FireMarker(loc, FireMarkType.falsePos)); if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel)); }); industries.forEach((industry) { // print(fire['geo']['coordinates']); var coords = industry['geo']['coordinates']; - var loc = LatLng(coords[1], coords[0]); + var loc = LatLng(double.parse(coords[1]), double.parse(coords[0])); markers.add(FireMarker(loc, FireMarkType.industry)); if (calibrate) markers.add(FireMarker(loc, FireMarkType.pixel)); }); fires.forEach((fire) { - var loc = new LatLng(fire['lat'], fire['lon']); + var loc = new LatLng(double.parse(fire['lat']), double.parse(fire['lon'])); markers.add( FireMarker(loc, FireMarkType.fire, () => print('marker pressed'))); markers.add(FireMarker(loc, FireMarkType.pixel)); From d40859c5d836394deb75fa2c80794049d624c530 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Fri, 17 Aug 2018 06:48:50 +0200 Subject: [PATCH 8/9] Localize app_name --- android/app/src/main/AndroidManifest-Sample.xml | 4 ++-- android/app/src/main/res/values-es/strings.xml | 4 ++++ android/app/src/main/res/values-gl/strings.xml | 4 ++++ android/app/src/main/res/values/strings.xml | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 android/app/src/main/res/values-es/strings.xml create mode 100644 android/app/src/main/res/values-gl/strings.xml create mode 100644 android/app/src/main/res/values/strings.xml diff --git a/android/app/src/main/AndroidManifest-Sample.xml b/android/app/src/main/AndroidManifest-Sample.xml index 9db35fe..aafa1ca 100644 --- a/android/app/src/main/AndroidManifest-Sample.xml +++ b/android/app/src/main/AndroidManifest-Sample.xml @@ -16,7 +16,7 @@ FlutterApplication and put your custom class here. --> + android:value="true" /> diff --git a/android/app/src/main/res/values-es/strings.xml b/android/app/src/main/res/values-es/strings.xml new file mode 100644 index 0000000..18a4518 --- /dev/null +++ b/android/app/src/main/res/values-es/strings.xml @@ -0,0 +1,4 @@ + + + ¡Tod@s contra el Fuego! + diff --git a/android/app/src/main/res/values-gl/strings.xml b/android/app/src/main/res/values-gl/strings.xml new file mode 100644 index 0000000..b509cd1 --- /dev/null +++ b/android/app/src/main/res/values-gl/strings.xml @@ -0,0 +1,4 @@ + + + Tod@s contra o Lume! + diff --git a/android/app/src/main/res/values/strings.xml b/android/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..65089d9 --- /dev/null +++ b/android/app/src/main/res/values/strings.xml @@ -0,0 +1,4 @@ + + + All Against The Fire! + From 46026917c721b6dd0c2541741cf7442e7d531512 Mon Sep 17 00:00:00 2001 From: "Vicente J. Ruiz Jurado" Date: Fri, 17 Aug 2018 06:49:44 +0200 Subject: [PATCH 9/9] Fetch fire data on new locations --- lib/redux/fetchDataMiddleware.dart | 65 +++++++++++++++++------------- 1 file changed, 37 insertions(+), 28 deletions(-) diff --git a/lib/redux/fetchDataMiddleware.dart b/lib/redux/fetchDataMiddleware.dart index a939802..4b419c6 100644 --- a/lib/redux/fetchDataMiddleware.dart +++ b/lib/redux/fetchDataMiddleware.dart @@ -58,6 +58,7 @@ void fetchDataMiddleware(Store 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 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 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); } @@ -150,12 +142,12 @@ void fetchDataMiddleware(Store store, action, NextDispatcher next) { if (action is FetchYourLocationsAction) { // Use the api to fetch the YourLocations loadYourLocations().then((localLocations) { - api - .fetchYourLocations(store.state) - .then((List subscribedLocations) { - // If it succeeds, dispatch a success action with the YourLocations. - // Our reducer will then update the State using these YourLocations. - // print('Subscribed to: ${subscribedLocations.length}'); + api + .fetchYourLocations(store.state) + .then((List subscribedLocations) { + // If it succeeds, dispatch a success action with the YourLocations. + // Our reducer will then update the State using these YourLocations. + // print('Subscribed to: ${subscribedLocations.length}'); if (subscribedLocations is List) { // unsubscribe all locally to sync the subs state localLocations.forEach((location) => location.subscribed = false); @@ -173,12 +165,12 @@ void fetchDataMiddleware(Store store, action, NextDispatcher next) { localLocations.forEach((yl) { api - .getFiresInLocation( - state: store.state, - lat: yl.lat, - lon: yl.lon, - distance: yl.distance) - .then((value) { + .getFiresInLocation( + state: store.state, + lat: yl.lat, + lon: yl.lon, + distance: yl.distance) + .then((value) { yl.currentNumFires = value.numFires; store.dispatch(new UpdateYourLocationAction(yl)); }); @@ -211,18 +203,21 @@ void fetchDataMiddleware(Store 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 store, action, NextDispatcher next) { next(action); } +void getFiresStatsInLocation(Store 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 store, FireNotification notif) { api .getFiresInLocation(