diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index 2a8540545..8bb628e7e 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -162,7 +162,7 @@ abstract class AppState implements Built { BuiltMap getEntityMap(EntityType type) { switch (type) { case EntityType.product: - return projectState.map; + return productState.map; case EntityType.client: return clientState.map; case EntityType.invoice: diff --git a/lib/redux/ui/ui_reducer.dart b/lib/redux/ui/ui_reducer.dart index c750eae24..d2e5dd6f9 100644 --- a/lib/redux/ui/ui_reducer.dart +++ b/lib/redux/ui/ui_reducer.dart @@ -8,6 +8,7 @@ import 'package:invoiceninja_flutter/redux/company/company_state.dart'; import 'package:invoiceninja_flutter/redux/dashboard/dashboard_reducer.dart'; import 'package:invoiceninja_flutter/redux/group/group_actions.dart'; import 'package:invoiceninja_flutter/redux/invoice/invoice_actions.dart'; +import 'package:invoiceninja_flutter/redux/product/product_actions.dart'; import 'package:invoiceninja_flutter/redux/settings/settings_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_state.dart'; @@ -85,6 +86,9 @@ Reducer> historyReducer = combineReducers([ TypedReducer, ViewClient>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.clientId, entityType: EntityType.client))), + TypedReducer, ViewProduct>((historyList, action) => + _addToHistory(historyList, + HistoryRecord(id: action.productId, entityType: EntityType.product))), TypedReducer, ViewInvoice>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.invoiceId, entityType: EntityType.invoice))), diff --git a/lib/ui/app/history_drawer.dart b/lib/ui/app/history_drawer.dart index 38c936b75..b04fb8d3c 100644 --- a/lib/ui/app/history_drawer.dart +++ b/lib/ui/app/history_drawer.dart @@ -1,5 +1,3 @@ -import 'dart:math'; - import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_redux/flutter_redux.dart'; @@ -21,8 +19,26 @@ class HistoryDrawer extends StatelessWidget { final localization = AppLocalization.of(context); final store = StoreProvider.of(context); final state = store.state; - final history = state.uiState.historyList - .sublist(0, min(state.uiState.historyList.length, 50)); + + final widgets = []; + for (var history in state.uiState.historyList) { + if (widgets.length > 50) { + break; + } + + final entity = state.getEntityMap(history.entityType)[history.id]; + + if (entity == null) { + continue; + } + + widgets.add(ListTile( + key: ValueKey('__${history.id}_${history.entityType}__'), + leading: Icon(getEntityIcon(history.entityType)), + title: Text(entity.listDisplayName), + subtitle: Text(localization.lookup('${history.entityType}')), + )); + } return Drawer( child: Scaffold( @@ -42,14 +58,7 @@ class HistoryDrawer extends StatelessWidget { ], ), body: ListView( - children: history.map((history) { - final entity = state.getEntityMap(history.entityType)[history.id]; - return ListTile( - leading: Icon(getEntityIcon(history.entityType)), - title: Text(entity.listDisplayName), - subtitle: Text(localization.lookup('${history.entityType}')), - ); - }).toList(), + children: widgets, ), ), );