diff --git a/lib/data/models/entities.dart b/lib/data/models/entities.dart index a39dd8f43..367c13a0d 100644 --- a/lib/data/models/entities.dart +++ b/lib/data/models/entities.dart @@ -36,7 +36,7 @@ class DashboardEntity extends Object with _$DashboardEntitySerializerMixin { double paidToDate; - DashboardEntity(this.paidToDate); + DashboardEntity([this.paidToDate]); factory DashboardEntity.fromJson(Map json) => _$DashboardEntityFromJson(json); } diff --git a/lib/redux/app/app_reducer.dart b/lib/redux/app/app_reducer.dart index e9825b956..117be977a 100644 --- a/lib/redux/app/app_reducer.dart +++ b/lib/redux/app/app_reducer.dart @@ -1,7 +1,8 @@ import 'package:invoiceninja/redux/app/app_state.dart'; import 'package:invoiceninja/redux/app/loading_reducer.dart'; -import 'package:invoiceninja/redux/product/product_reducer.dart'; import 'package:invoiceninja/redux/auth/auth_reducer.dart'; +import 'package:invoiceninja/redux/dashboard/dashboard_reducer.dart'; +import 'package:invoiceninja/redux/product/product_reducer.dart'; // We create the State reducer by combining many smaller reducers into one! AppState appReducer(AppState state, action) { @@ -18,7 +19,8 @@ AppState appReducer(AppState state, action) { return AppState( isLoading: loadingReducer(state.isLoading, action), - products: productsReducer(state.products, action), auth: authReducer(state.auth, action), + dashboard: dashboardReducer(state.dashboard, action), + products: productsReducer(state.products, action), ); } diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index de2490417..7a68c85f3 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -6,12 +6,15 @@ import 'package:invoiceninja/redux/auth/auth_state.dart'; class AppState { final bool isLoading; final AuthState auth; + final DashboardEntity dashboard; final List products; AppState( {this.isLoading = false, this.products = const [], - AuthState auth}): + DashboardEntity dashboard, + AuthState auth}) : + dashboard = dashboard ?? new DashboardEntity(), auth = auth ?? new AuthState(); @@ -31,17 +34,20 @@ class AppState { bool isLoading, AuthState auth, List products, + DashboardEntity dashboard, }) { return AppState( isLoading: isLoading ?? this.isLoading, auth: auth ?? this.auth, products: products ?? this.products, + dashboard: dashboard ?? this.dashboard, ); } @override int get hashCode => products.hashCode ^ + dashboard.hashCode ^ auth.hashCode ^ isLoading.hashCode; @@ -50,6 +56,7 @@ class AppState { identical(this, other) || other is AppState && runtimeType == other.runtimeType && + dashboard == other.dashboard && products == other.products && auth == other.auth && isLoading == other.isLoading; diff --git a/lib/redux/dashboard/dashboard_reducer.dart b/lib/redux/dashboard/dashboard_reducer.dart new file mode 100644 index 000000000..afb800e46 --- /dev/null +++ b/lib/redux/dashboard/dashboard_reducer.dart @@ -0,0 +1,16 @@ +import 'package:redux/redux.dart'; +import 'package:invoiceninja/redux/dashboard/dashboard_actions.dart'; +import 'package:invoiceninja/data/models/models.dart'; + +final dashboardReducer = combineReducers([ + TypedReducer(_setLoadedDashboards), + TypedReducer(_setNoDashboards), +]); + +DashboardEntity _setLoadedDashboards(DashboardEntity data, DashboardLoadedAction action) { + return action.data; +} + +DashboardEntity _setNoDashboards(DashboardEntity data, DashboardNotLoadedAction action) { + return null; +}