Dashboard...

This commit is contained in:
unknown 2018-05-22 07:33:46 -07:00
parent 00043e21f2
commit ade297b354
4 changed files with 29 additions and 4 deletions

View File

@ -36,7 +36,7 @@ class DashboardEntity extends Object with _$DashboardEntitySerializerMixin {
double paidToDate; double paidToDate;
DashboardEntity(this.paidToDate); DashboardEntity([this.paidToDate]);
factory DashboardEntity.fromJson(Map<String, dynamic> json) => _$DashboardEntityFromJson(json); factory DashboardEntity.fromJson(Map<String, dynamic> json) => _$DashboardEntityFromJson(json);
} }

View File

@ -1,7 +1,8 @@
import 'package:invoiceninja/redux/app/app_state.dart'; import 'package:invoiceninja/redux/app/app_state.dart';
import 'package:invoiceninja/redux/app/loading_reducer.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/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! // We create the State reducer by combining many smaller reducers into one!
AppState appReducer(AppState state, action) { AppState appReducer(AppState state, action) {
@ -18,7 +19,8 @@ AppState appReducer(AppState state, action) {
return AppState( return AppState(
isLoading: loadingReducer(state.isLoading, action), isLoading: loadingReducer(state.isLoading, action),
products: productsReducer(state.products, action),
auth: authReducer(state.auth, action), auth: authReducer(state.auth, action),
dashboard: dashboardReducer(state.dashboard, action),
products: productsReducer(state.products, action),
); );
} }

View File

@ -6,12 +6,15 @@ import 'package:invoiceninja/redux/auth/auth_state.dart';
class AppState { class AppState {
final bool isLoading; final bool isLoading;
final AuthState auth; final AuthState auth;
final DashboardEntity dashboard;
final List<ProductEntity> products; final List<ProductEntity> products;
AppState( AppState(
{this.isLoading = false, {this.isLoading = false,
this.products = const [], this.products = const [],
DashboardEntity dashboard,
AuthState auth}) : AuthState auth}) :
dashboard = dashboard ?? new DashboardEntity(),
auth = auth ?? new AuthState(); auth = auth ?? new AuthState();
@ -31,17 +34,20 @@ class AppState {
bool isLoading, bool isLoading,
AuthState auth, AuthState auth,
List<ProductEntity> products, List<ProductEntity> products,
DashboardEntity dashboard,
}) { }) {
return AppState( return AppState(
isLoading: isLoading ?? this.isLoading, isLoading: isLoading ?? this.isLoading,
auth: auth ?? this.auth, auth: auth ?? this.auth,
products: products ?? this.products, products: products ?? this.products,
dashboard: dashboard ?? this.dashboard,
); );
} }
@override @override
int get hashCode => int get hashCode =>
products.hashCode ^ products.hashCode ^
dashboard.hashCode ^
auth.hashCode ^ auth.hashCode ^
isLoading.hashCode; isLoading.hashCode;
@ -50,6 +56,7 @@ class AppState {
identical(this, other) || identical(this, other) ||
other is AppState && other is AppState &&
runtimeType == other.runtimeType && runtimeType == other.runtimeType &&
dashboard == other.dashboard &&
products == other.products && products == other.products &&
auth == other.auth && auth == other.auth &&
isLoading == other.isLoading; isLoading == other.isLoading;

View File

@ -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<DashboardEntity>([
TypedReducer<DashboardEntity, DashboardLoadedAction>(_setLoadedDashboards),
TypedReducer<DashboardEntity, DashboardNotLoadedAction>(_setNoDashboards),
]);
DashboardEntity _setLoadedDashboards(DashboardEntity data, DashboardLoadedAction action) {
return action.data;
}
DashboardEntity _setNoDashboards(DashboardEntity data, DashboardNotLoadedAction action) {
return null;
}