More work with fire notifications

This commit is contained in:
Vicente J. Ruiz Jurado 2018-07-31 12:51:10 +02:00
parent 5fdaf239c0
commit 9dd8a7de97
24 changed files with 512 additions and 288 deletions

View file

@ -41,6 +41,7 @@ class OnUserLangAction extends AppActions {
class FetchFireNotificationsSucceededAction extends AppActions {
final List<FireNotification> fetchedFireNotifications;
final int unreadCount;
FetchFireNotificationsSucceededAction(this.fetchedFireNotifications);
FetchFireNotificationsSucceededAction(this.fetchedFireNotifications, this.unreadCount);
}

View file

@ -6,7 +6,16 @@ AppState appReducer(AppState state, action) {
return state.copyWith(yourLocations: action.fetchedYourLocations);
}
if (action is FetchFireNotificationsSucceededAction) {
return state.copyWith(fireNotifications: action.fetchedFireNotifications);
return state.copyWith(fireNotifications: action.fetchedFireNotifications,
fireNotificationsUnread: action.unreadCount);
}
if (action is AddedFireNotificationAction)
return state.copyWith(
fireNotificationsUnread: state.fireNotificationsUnread + 1);
if (action is ReadedFireNotificationAction)
return state.copyWith(
fireNotificationsUnread: state.fireNotificationsUnread - 1);
return state;
}
}

View file

@ -1,5 +1,6 @@
import 'package:bson_objectid/bson_objectid.dart';
import 'package:fires_flutter/models/yourLocation.dart';
import 'package:fires_flutter/models/fireNotification.dart';
import 'package:flutter_simple_dependency_injection/injector.dart';
import 'package:just_debounce_it/just_debounce_it.dart';
import 'package:redux/redux.dart';
@ -161,8 +162,12 @@ void fetchDataMiddleware(Store<AppState> store, action, NextDispatcher next) {
if (action is FetchFireNotificationsAction) {
loadFireNotifications().then((fireNotifications) {
int unread = 0;
for (FireNotification notif in fireNotifications) {
if (!notif.read) { unread++; }
}
store.dispatch(
new FetchFireNotificationsSucceededAction(fireNotifications));
new FetchFireNotificationsSucceededAction(fireNotifications, unread));
persistFireNotifications(fireNotifications);
});
}

View file

@ -44,7 +44,7 @@ FireMapState _showYourLocationMap(
status: action.loc.subscribed
? FireMapStatus.unsubscribe
: FireMapStatus.view,
yourLocation: action.loc);
yourLocation: action.loc, fireNotication: null);
}
FireMapState _showFireNotificationMap(

View file

@ -16,7 +16,7 @@ final fireNotificationReducer = combineReducers<List<FireNotification>>([
List<FireNotification> _receivedFireNotification(
List<FireNotification> notifications, AddedFireNotificationAction action) {
return new List.from(notifications)..add(action.notif);
return new List.from(notifications)..insert(0, action.notif);
}
List<FireNotification> _deletedFireNotification(

View file

@ -1,29 +1,28 @@
import '../models/appState.dart';
import 'appReducer.dart';
import 'errorReducer.dart';
import 'fireMapReducer.dart';
import 'fireNotificationReducer.dart';
import 'loadedReducer.dart';
import 'loadingReducer.dart';
import 'userReducer.dart';
import 'yourLocationsReducer.dart';
import 'actions.dart';
import 'appReducer.dart';
import 'fireNotificationReducer.dart';
// We create the State reducer by combining many smaller reducers into one!
AppState appStateReducer(AppState prevState, action) {
var state = prevState;
if (action is AppActions)
state = appReducer(prevState, action);
var state = appReducer(prevState, action);
return AppState(
yourLocations: yourLocationsReducer(state.yourLocations, action),
fireNotifications: fireNotificationReducer(state.fireNotifications, action),
yourLocations: yourLocationsReducer(state.yourLocations, action),
fireNotifications:
fireNotificationReducer(state.fireNotifications, action),
fireNotificationsUnread: state.fireNotificationsUnread,
user: userReducer(state.user, action),
isLoading: loadingReducer(state.isLoading, action),
isLoaded: loadedReducer(state.isLoaded, action),
error: errorReducer(state.error, action),
fireMapState: fireMapReducer(state.fireMapState, action),
firesApiKey: state.firesApiKey,
firesApiUrl: state.firesApiUrl,
gmapKey: state.gmapKey
);
firesApiKey: state.firesApiKey,
firesApiUrl: state.firesApiUrl,
serverUrl: state.serverUrl,
gmapKey: state.gmapKey);
}