From f3dbf0be5892d4d6298ed04cb577a81aa5d12cda Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 6 Jun 2023 17:36:22 +0300 Subject: [PATCH] Fix for back button --- lib/redux/app/app_actions.dart | 38 +++++----- lib/redux/client/client_actions.dart | 2 + lib/redux/credit/credit_actions.dart | 6 +- lib/redux/expense/expense_actions.dart | 6 +- lib/redux/invoice/invoice_actions.dart | 6 +- lib/redux/payment/payment_actions.dart | 6 +- lib/redux/product/product_actions.dart | 6 +- lib/redux/project/project_actions.dart | 6 +- .../purchase_order_actions.dart | 6 +- lib/redux/quote/quote_actions.dart | 6 +- .../recurring_expense_actions.dart | 2 + .../recurring_invoice_actions.dart | 2 + lib/redux/task/task_actions.dart | 3 +- .../transaction/transaction_actions.dart | 6 +- lib/redux/ui/pref_reducer.dart | 72 ++++++++++++------- lib/redux/ui/pref_state.dart | 5 ++ lib/redux/ui/pref_state.g.dart | 24 ++++++- lib/redux/vendor/vendor_actions.dart | 6 +- lib/ui/app/history_drawer.dart | 5 ++ lib/ui/app/main_screen.dart | 3 +- lib/ui/app/menu_drawer.dart | 4 +- lib/ui/app/tables/entity_list.dart | 20 ++++-- stubs/redux/stub/stub_actions | 2 + 23 files changed, 182 insertions(+), 60 deletions(-) diff --git a/lib/redux/app/app_actions.dart b/lib/redux/app/app_actions.dart index 957e27809..81bad23d7 100644 --- a/lib/redux/app/app_actions.dart +++ b/lib/redux/app/app_actions.dart @@ -97,6 +97,12 @@ class SwitchListTableLayout implements PersistUI, PersistPrefs {} class PopLastHistory implements PersistUI {} +class UpdateLastHistory implements PersistUI { + const UpdateLastHistory(this.page); + + final int page; +} + class DismissNativeWarning implements PersistUI {} class DismissNativeWarningPermanently implements PersistUI, PersistPrefs {} @@ -329,6 +335,7 @@ void filterByEntity({ void viewEntitiesByType({ @required EntityType entityType, BaseEntity filterEntity, + int page = 0, }) { final store = StoreProvider.of(navigatorKey.currentContext); final uiState = store.state.uiState; @@ -371,13 +378,13 @@ void viewEntitiesByType({ ); break; case EntityType.client: - action = ViewClientList(); + action = ViewClientList(page: page); break; case EntityType.user: action = ViewUserList(); break; case EntityType.project: - action = ViewProjectList(); + action = ViewProjectList(page: page); break; case EntityType.taxRate: action = ViewTaxRateList(); @@ -386,25 +393,25 @@ void viewEntitiesByType({ action = ViewCompanyGatewayList(); break; case EntityType.invoice: - action = ViewInvoiceList(); + action = ViewInvoiceList(page: page); break; case EntityType.quote: - action = ViewQuoteList(); + action = ViewQuoteList(page: page); break; case EntityType.vendor: - action = ViewVendorList(); + action = ViewVendorList(page: page); break; case EntityType.product: - action = ViewProductList(); + action = ViewProductList(page: page); break; case EntityType.task: - action = ViewTaskList(); + action = ViewTaskList(page: page); break; case EntityType.expense: - action = ViewExpenseList(); + action = ViewExpenseList(page: page); break; case EntityType.payment: - action = ViewPaymentList(); + action = ViewPaymentList(page: page); break; case EntityType.group: action = ViewGroupList(); @@ -416,20 +423,17 @@ void viewEntitiesByType({ case EntityType.transactionRule: action = ViewTransactionRuleList(); break; - case EntityType.transaction: - action = ViewTransactionList(); + action = ViewTransactionList(page: page); break; - case EntityType.bankAccount: action = ViewBankAccountList(); break; - case EntityType.purchaseOrder: - action = ViewPurchaseOrderList(); + action = ViewPurchaseOrderList(page: page); break; case EntityType.recurringExpense: - action = ViewRecurringExpenseList(); + action = ViewRecurringExpenseList(page: page); break; case EntityType.subscription: action = ViewSubscriptionList(); @@ -441,7 +445,7 @@ void viewEntitiesByType({ action = ViewExpenseCategoryList(); break; case EntityType.recurringInvoice: - action = ViewRecurringInvoiceList(); + action = ViewRecurringInvoiceList(page: page); break; case EntityType.webhook: action = ViewWebhookList(); @@ -456,7 +460,7 @@ void viewEntitiesByType({ action = ViewDesignList(); break; case EntityType.credit: - action = ViewCreditList(); + action = ViewCreditList(page: page); break; } diff --git a/lib/redux/client/client_actions.dart b/lib/redux/client/client_actions.dart index 3fde5a0aa..559fea064 100644 --- a/lib/redux/client/client_actions.dart +++ b/lib/redux/client/client_actions.dart @@ -26,9 +26,11 @@ import 'package:invoiceninja_flutter/utils/localization.dart'; class ViewClientList implements PersistUI { ViewClientList({ this.force = false, + this.page = 0, }); final bool force; + final int page; } class ViewClient implements PersistUI, PersistPrefs { diff --git a/lib/redux/credit/credit_actions.dart b/lib/redux/credit/credit_actions.dart index e4ba5ffe6..4b1b25060 100644 --- a/lib/redux/credit/credit_actions.dart +++ b/lib/redux/credit/credit_actions.dart @@ -29,9 +29,13 @@ import 'package:invoiceninja_flutter/data/web_client.dart'; import 'package:printing/printing.dart'; class ViewCreditList implements PersistUI { - ViewCreditList({this.force = false}); + ViewCreditList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewCredit implements PersistUI, PersistPrefs { diff --git a/lib/redux/expense/expense_actions.dart b/lib/redux/expense/expense_actions.dart index 99df9decc..c3c26d483 100644 --- a/lib/redux/expense/expense_actions.dart +++ b/lib/redux/expense/expense_actions.dart @@ -23,9 +23,13 @@ import 'package:invoiceninja_flutter/utils/dialogs.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; class ViewExpenseList implements PersistUI { - ViewExpenseList({this.force = false}); + ViewExpenseList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewExpense implements PersistUI, PersistPrefs { diff --git a/lib/redux/invoice/invoice_actions.dart b/lib/redux/invoice/invoice_actions.dart index f27e77689..34d2c9579 100644 --- a/lib/redux/invoice/invoice_actions.dart +++ b/lib/redux/invoice/invoice_actions.dart @@ -31,9 +31,13 @@ import 'package:invoiceninja_flutter/data/web_client.dart'; import 'package:printing/printing.dart'; class ViewInvoiceList implements PersistUI { - ViewInvoiceList({this.force = false}); + ViewInvoiceList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewInvoice implements PersistUI, PersistPrefs { diff --git a/lib/redux/payment/payment_actions.dart b/lib/redux/payment/payment_actions.dart index fbba6c63d..c3fbbdad8 100644 --- a/lib/redux/payment/payment_actions.dart +++ b/lib/redux/payment/payment_actions.dart @@ -18,9 +18,13 @@ import 'package:invoiceninja_flutter/utils/completers.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; class ViewPaymentList implements PersistUI { - ViewPaymentList({this.force = false}); + ViewPaymentList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewPayment implements PersistUI, PersistPrefs { diff --git a/lib/redux/product/product_actions.dart b/lib/redux/product/product_actions.dart index 61d1164d2..3783e742d 100644 --- a/lib/redux/product/product_actions.dart +++ b/lib/redux/product/product_actions.dart @@ -23,9 +23,13 @@ import 'package:invoiceninja_flutter/utils/localization.dart'; import '../document/document_actions.dart'; class ViewProductList implements PersistUI { - ViewProductList({this.force = false}); + ViewProductList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewProduct implements PersistUI, PersistPrefs { diff --git a/lib/redux/project/project_actions.dart b/lib/redux/project/project_actions.dart index 9839207f8..f69cc4936 100644 --- a/lib/redux/project/project_actions.dart +++ b/lib/redux/project/project_actions.dart @@ -22,9 +22,13 @@ import 'package:invoiceninja_flutter/utils/dialogs.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; class ViewProjectList implements PersistUI { - ViewProjectList({this.force = false}); + ViewProjectList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewProject implements PersistUI, PersistPrefs { diff --git a/lib/redux/purchase_order/purchase_order_actions.dart b/lib/redux/purchase_order/purchase_order_actions.dart index 4e7dc35ff..e78f215c3 100644 --- a/lib/redux/purchase_order/purchase_order_actions.dart +++ b/lib/redux/purchase_order/purchase_order_actions.dart @@ -20,9 +20,13 @@ import 'package:printing/printing.dart'; import 'package:url_launcher/url_launcher.dart'; class ViewPurchaseOrderList implements PersistUI { - ViewPurchaseOrderList({this.force = false}); + ViewPurchaseOrderList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewPurchaseOrder implements PersistUI, PersistPrefs { diff --git a/lib/redux/quote/quote_actions.dart b/lib/redux/quote/quote_actions.dart index 1614c0494..b5534178b 100644 --- a/lib/redux/quote/quote_actions.dart +++ b/lib/redux/quote/quote_actions.dart @@ -29,9 +29,13 @@ import 'package:invoiceninja_flutter/data/web_client.dart'; import 'package:printing/printing.dart'; class ViewQuoteList implements PersistUI { - ViewQuoteList({this.force = false}); + ViewQuoteList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewQuote implements PersistUI, PersistPrefs { diff --git a/lib/redux/recurring_expense/recurring_expense_actions.dart b/lib/redux/recurring_expense/recurring_expense_actions.dart index 938b29514..f325cff00 100644 --- a/lib/redux/recurring_expense/recurring_expense_actions.dart +++ b/lib/redux/recurring_expense/recurring_expense_actions.dart @@ -22,9 +22,11 @@ import 'package:invoiceninja_flutter/utils/localization.dart'; class ViewRecurringExpenseList implements PersistUI { ViewRecurringExpenseList({ this.force = false, + this.page = 0, }); final bool force; + final int page; } class ViewRecurringExpense implements PersistUI, PersistPrefs { diff --git a/lib/redux/recurring_invoice/recurring_invoice_actions.dart b/lib/redux/recurring_invoice/recurring_invoice_actions.dart index 62a7b7377..840cfbdde 100644 --- a/lib/redux/recurring_invoice/recurring_invoice_actions.dart +++ b/lib/redux/recurring_invoice/recurring_invoice_actions.dart @@ -27,9 +27,11 @@ import 'package:invoiceninja_flutter/utils/localization.dart'; class ViewRecurringInvoiceList implements PersistUI { ViewRecurringInvoiceList({ this.force = false, + this.page = 0, }); final bool force; + final int page; } class ViewRecurringInvoice implements PersistUI, PersistPrefs { diff --git a/lib/redux/task/task_actions.dart b/lib/redux/task/task_actions.dart index 3c36640f1..f1c029aa6 100644 --- a/lib/redux/task/task_actions.dart +++ b/lib/redux/task/task_actions.dart @@ -22,9 +22,10 @@ import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; class ViewTaskList implements PersistUI { - ViewTaskList({this.force = false}); + ViewTaskList({this.force = false, this.page = 0,}); final bool force; + final int page; } class ViewTask implements PersistUI, PersistPrefs { diff --git a/lib/redux/transaction/transaction_actions.dart b/lib/redux/transaction/transaction_actions.dart index 1a5ddb638..d82a27720 100644 --- a/lib/redux/transaction/transaction_actions.dart +++ b/lib/redux/transaction/transaction_actions.dart @@ -10,9 +10,13 @@ import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart'; class ViewTransactionList implements PersistUI { - ViewTransactionList({this.force = false}); + ViewTransactionList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewTransaction implements PersistUI, PersistPrefs { diff --git a/lib/redux/ui/pref_reducer.dart b/lib/redux/ui/pref_reducer.dart index eb4d20f08..ac2bf882a 100644 --- a/lib/redux/ui/pref_reducer.dart +++ b/lib/redux/ui/pref_reducer.dart @@ -536,6 +536,18 @@ Reducer> historyReducer = combineReducers([ } }, ), + TypedReducer, UpdateLastHistory>( + (historyList, action) { + if (historyList.isEmpty) { + return historyList; + } + + final history = historyList.first; + + return historyList.rebuild( + (b) => b..[0] = history.rebuild((b) => b.page = action.page)); + }, + ), TypedReducer, ViewDashboard>((historyList, action) => _addToHistory( historyList, HistoryRecord(entityType: EntityType.dashboard))), @@ -551,9 +563,9 @@ Reducer> historyReducer = combineReducers([ TypedReducer, ViewClient>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.clientId, entityType: EntityType.client))), - TypedReducer, ViewClientList>((historyList, - action) => - _addToHistory(historyList, HistoryRecord(entityType: EntityType.client))), + TypedReducer, ViewClientList>( + (historyList, action) => _addToHistory(historyList, + HistoryRecord(entityType: EntityType.client, page: action.page))), TypedReducer, EditClient>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.client.id, entityType: EntityType.client))), @@ -561,8 +573,8 @@ Reducer> historyReducer = combineReducers([ _addToHistory(historyList, HistoryRecord(id: action.productId, entityType: EntityType.product))), TypedReducer, ViewProductList>( - (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.product))), + (historyList, action) => _addToHistory(historyList, + HistoryRecord(entityType: EntityType.product, page: action.page))), TypedReducer, EditProduct>((historyList, action) => _addToHistory( historyList, @@ -572,8 +584,8 @@ Reducer> historyReducer = combineReducers([ _addToHistory(historyList, HistoryRecord(id: action.invoiceId, entityType: EntityType.invoice))), TypedReducer, ViewInvoiceList>( - (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.invoice))), + (historyList, action) => _addToHistory(historyList, + HistoryRecord(entityType: EntityType.invoice, page: action.page))), TypedReducer, EditInvoice>((historyList, action) => _addToHistory( historyList, @@ -583,8 +595,8 @@ Reducer> historyReducer = combineReducers([ _addToHistory(historyList, HistoryRecord(id: action.paymentId, entityType: EntityType.payment))), TypedReducer, ViewPaymentList>( - (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.payment))), + (historyList, action) => _addToHistory(historyList, + HistoryRecord(entityType: EntityType.payment, page: action.page))), TypedReducer, EditPayment>((historyList, action) => _addToHistory( historyList, @@ -594,7 +606,8 @@ Reducer> historyReducer = combineReducers([ _addToHistory(historyList, HistoryRecord(id: action.quoteId, entityType: EntityType.quote))), TypedReducer, ViewQuoteList>((historyList, action) => - _addToHistory(historyList, HistoryRecord(entityType: EntityType.quote))), + _addToHistory(historyList, + HistoryRecord(entityType: EntityType.quote, page: action.page))), TypedReducer, EditQuote>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.quote.id, entityType: EntityType.quote))), @@ -602,7 +615,8 @@ Reducer> historyReducer = combineReducers([ _addToHistory(historyList, HistoryRecord(id: action.taskId, entityType: EntityType.task))), TypedReducer, ViewTaskList>((historyList, action) => - _addToHistory(historyList, HistoryRecord(entityType: EntityType.task))), + _addToHistory(historyList, + HistoryRecord(entityType: EntityType.task, page: action.page))), TypedReducer, EditTask>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.task.id, entityType: EntityType.task))), @@ -610,8 +624,8 @@ Reducer> historyReducer = combineReducers([ _addToHistory(historyList, HistoryRecord(id: action.projectId, entityType: EntityType.project))), TypedReducer, ViewProjectList>( - (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.project))), + (historyList, action) => _addToHistory(historyList, + HistoryRecord(entityType: EntityType.project, page: action.page))), TypedReducer, EditProject>((historyList, action) => _addToHistory( historyList, @@ -620,9 +634,9 @@ Reducer> historyReducer = combineReducers([ TypedReducer, ViewVendor>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.vendorId, entityType: EntityType.vendor))), - TypedReducer, ViewVendorList>((historyList, - action) => - _addToHistory(historyList, HistoryRecord(entityType: EntityType.vendor))), + TypedReducer, ViewVendorList>( + (historyList, action) => _addToHistory(historyList, + HistoryRecord(entityType: EntityType.vendor, page: action.page))), TypedReducer, EditVendor>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.vendor.id, entityType: EntityType.vendor))), @@ -630,8 +644,8 @@ Reducer> historyReducer = combineReducers([ _addToHistory(historyList, HistoryRecord(id: action.expenseId, entityType: EntityType.expense))), TypedReducer, ViewExpenseList>( - (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.expense))), + (historyList, action) => _addToHistory(historyList, + HistoryRecord(entityType: EntityType.expense, page: action.page))), TypedReducer, EditExpense>((historyList, action) => _addToHistory( historyList, @@ -706,7 +720,9 @@ Reducer> historyReducer = combineReducers([ id: action.transactionId, entityType: EntityType.transaction))), TypedReducer, ViewTransactionList>( (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.transaction))), + historyList, + HistoryRecord( + entityType: EntityType.transaction, page: action.page))), TypedReducer, EditTransaction>( (historyList, action) => _addToHistory( historyList, @@ -729,7 +745,9 @@ Reducer> historyReducer = combineReducers([ entityType: EntityType.purchaseOrder))), TypedReducer, ViewPurchaseOrderList>( (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.purchaseOrder))), + historyList, + HistoryRecord( + entityType: EntityType.purchaseOrder, page: action.page))), TypedReducer, EditPurchaseOrder>( (historyList, action) => _addToHistory( historyList, @@ -744,7 +762,9 @@ Reducer> historyReducer = combineReducers([ entityType: EntityType.recurringExpense))), TypedReducer, ViewRecurringExpenseList>( (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.recurringExpense))), + historyList, + HistoryRecord( + entityType: EntityType.recurringExpense, page: action.page))), TypedReducer, EditRecurringExpense>( (historyList, action) => _addToHistory( historyList, @@ -803,7 +823,9 @@ Reducer> historyReducer = combineReducers([ entityType: EntityType.recurringInvoice))), TypedReducer, ViewRecurringInvoiceList>( (historyList, action) => _addToHistory( - historyList, HistoryRecord(entityType: EntityType.recurringInvoice))), + historyList, + HistoryRecord( + entityType: EntityType.recurringInvoice, page: action.page))), TypedReducer, EditRecurringInvoice>( (historyList, action) => _addToHistory( historyList, @@ -849,9 +871,9 @@ Reducer> historyReducer = combineReducers([ TypedReducer, ViewCredit>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.creditId, entityType: EntityType.credit))), - TypedReducer, ViewCreditList>((historyList, - action) => - _addToHistory(historyList, HistoryRecord(entityType: EntityType.credit))), + TypedReducer, ViewCreditList>( + (historyList, action) => _addToHistory(historyList, + HistoryRecord(entityType: EntityType.credit, page: action.page))), TypedReducer, EditCredit>((historyList, action) => _addToHistory(historyList, HistoryRecord(id: action.credit.id, entityType: EntityType.credit))), diff --git a/lib/redux/ui/pref_state.dart b/lib/redux/ui/pref_state.dart index b71da0a43..b2abaa795 100644 --- a/lib/redux/ui/pref_state.dart +++ b/lib/redux/ui/pref_state.dart @@ -394,11 +394,13 @@ abstract class HistoryRecord factory HistoryRecord({ @required EntityType entityType, String id, + int page, }) { return _$HistoryRecord._( id: id, entityType: entityType, timestamp: DateTime.now().millisecondsSinceEpoch, + page: page ?? 0, ); } @@ -413,6 +415,9 @@ abstract class HistoryRecord EntityType get entityType; + @nullable + int get page; + int get timestamp; DateTime get dateTime => DateTime.fromMillisecondsSinceEpoch(timestamp); diff --git a/lib/redux/ui/pref_state.g.dart b/lib/redux/ui/pref_state.g.dart index 23d0a4ede..4b1db9d2e 100644 --- a/lib/redux/ui/pref_state.g.dart +++ b/lib/redux/ui/pref_state.g.dart @@ -620,6 +620,12 @@ class _$HistoryRecordSerializer implements StructuredSerializer { ..add(serializers.serialize(value, specifiedType: const FullType(String))); } + value = object.page; + if (value != null) { + result + ..add('page') + ..add(serializers.serialize(value, specifiedType: const FullType(int))); + } return result; } @@ -643,6 +649,10 @@ class _$HistoryRecordSerializer implements StructuredSerializer { result.entityType = serializers.deserialize(value, specifiedType: const FullType(EntityType)) as EntityType; break; + case 'page': + result.page = serializers.deserialize(value, + specifiedType: const FullType(int)) as int; + break; case 'timestamp': result.timestamp = serializers.deserialize(value, specifiedType: const FullType(int)) as int; @@ -1557,12 +1567,15 @@ class _$HistoryRecord extends HistoryRecord { @override final EntityType entityType; @override + final int page; + @override final int timestamp; factory _$HistoryRecord([void Function(HistoryRecordBuilder) updates]) => (new HistoryRecordBuilder()..update(updates))._build(); - _$HistoryRecord._({this.id, this.entityType, this.timestamp}) : super._() { + _$HistoryRecord._({this.id, this.entityType, this.page, this.timestamp}) + : super._() { BuiltValueNullFieldError.checkNotNull( entityType, r'HistoryRecord', 'entityType'); BuiltValueNullFieldError.checkNotNull( @@ -1582,6 +1595,7 @@ class _$HistoryRecord extends HistoryRecord { return other is HistoryRecord && id == other.id && entityType == other.entityType && + page == other.page && timestamp == other.timestamp; } @@ -1592,6 +1606,7 @@ class _$HistoryRecord extends HistoryRecord { var _$hash = 0; _$hash = $jc(_$hash, id.hashCode); _$hash = $jc(_$hash, entityType.hashCode); + _$hash = $jc(_$hash, page.hashCode); _$hash = $jc(_$hash, timestamp.hashCode); _$hash = $jf(_$hash); return __hashCode ??= _$hash; @@ -1602,6 +1617,7 @@ class _$HistoryRecord extends HistoryRecord { return (newBuiltValueToStringHelper(r'HistoryRecord') ..add('id', id) ..add('entityType', entityType) + ..add('page', page) ..add('timestamp', timestamp)) .toString(); } @@ -1619,6 +1635,10 @@ class HistoryRecordBuilder EntityType get entityType => _$this._entityType; set entityType(EntityType entityType) => _$this._entityType = entityType; + int _page; + int get page => _$this._page; + set page(int page) => _$this._page = page; + int _timestamp; int get timestamp => _$this._timestamp; set timestamp(int timestamp) => _$this._timestamp = timestamp; @@ -1630,6 +1650,7 @@ class HistoryRecordBuilder if ($v != null) { _id = $v.id; _entityType = $v.entityType; + _page = $v.page; _timestamp = $v.timestamp; _$v = null; } @@ -1656,6 +1677,7 @@ class HistoryRecordBuilder id: id, entityType: BuiltValueNullFieldError.checkNotNull( entityType, r'HistoryRecord', 'entityType'), + page: page, timestamp: BuiltValueNullFieldError.checkNotNull( timestamp, r'HistoryRecord', 'timestamp')); replace(_$result); diff --git a/lib/redux/vendor/vendor_actions.dart b/lib/redux/vendor/vendor_actions.dart index 29e6a1270..bb4a2681e 100644 --- a/lib/redux/vendor/vendor_actions.dart +++ b/lib/redux/vendor/vendor_actions.dart @@ -21,9 +21,13 @@ import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:url_launcher/url_launcher.dart'; class ViewVendorList implements PersistUI { - ViewVendorList({this.force = false}); + ViewVendorList({ + this.force = false, + this.page = 0, + }); final bool force; + final int page; } class ViewVendor implements PersistUI, PersistPrefs { diff --git a/lib/ui/app/history_drawer.dart b/lib/ui/app/history_drawer.dart index abc2cdcd2..6a4d724b3 100644 --- a/lib/ui/app/history_drawer.dart +++ b/lib/ui/app/history_drawer.dart @@ -2,6 +2,7 @@ import 'dart:async'; // Flutter imports: +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; // Package imports: @@ -134,6 +135,10 @@ class _HistoryListTileState extends State { } } else if (history.id == null) { title = Text(localization.lookup(history.entityType.plural)); + + if (!kReleaseMode) { + subtitle = Text('Page: ${history.page}'); + } } else { entity = state.getEntityMap(history.entityType)[history.id] as BaseEntity; diff --git a/lib/ui/app/main_screen.dart b/lib/ui/app/main_screen.dart index 93c917859..68d6c2d84 100644 --- a/lib/ui/app/main_screen.dart +++ b/lib/ui/app/main_screen.dart @@ -314,7 +314,8 @@ class MainScreen extends StatelessWidget { break; default: if ((history.id ?? '').isEmpty) { - viewEntitiesByType(entityType: history.entityType); + viewEntitiesByType( + entityType: history.entityType, page: history.page); } else { viewEntityById( entityId: history.id, diff --git a/lib/ui/app/menu_drawer.dart b/lib/ui/app/menu_drawer.dart index 4f8e05b2a..a49c5fe59 100644 --- a/lib/ui/app/menu_drawer.dart +++ b/lib/ui/app/menu_drawer.dart @@ -134,8 +134,10 @@ class _MenuDrawerState extends State { break; default: if ((history.id ?? '').isEmpty) { + print('## PAGE: ${history.page}'); viewEntitiesByType( - entityType: history.entityType); + entityType: history.entityType, + page: history.page); } else { viewEntityById( entityId: history.id, diff --git a/lib/ui/app/tables/entity_list.dart b/lib/ui/app/tables/entity_list.dart index 09dc4c664..71507fd06 100644 --- a/lib/ui/app/tables/entity_list.dart +++ b/lib/ui/app/tables/entity_list.dart @@ -88,11 +88,19 @@ class _EntityListState extends State { // make sure the initial page shows the selected record final entityUIState = state.getUIState(entityType); - final selectedIndex = widget.entityList.indexOf(entityUIState.selectedId); final rowsPerPage = state.prefState.rowsPerPage; - if (selectedIndex >= 0) { - _firstRowIndex = (selectedIndex / rowsPerPage).floor() * rowsPerPage; + if ((entityUIState.selectedId ?? '').isNotEmpty) { + final selectedIndex = widget.entityList.indexOf(entityUIState.selectedId); + + if (selectedIndex >= 0) { + _firstRowIndex = (selectedIndex / rowsPerPage).floor() * rowsPerPage; + } + } else { + final history = state.historyList.first; + if (history.page != null) { + _firstRowIndex = history.page * rowsPerPage; + } } } @@ -279,7 +287,11 @@ class _EntityListState extends State { : 0, sortAscending: listUIState.sortAscending, rowsPerPage: state.prefState.rowsPerPage, - onPageChanged: (row) => _firstRowIndex = row, + onPageChanged: (row) { + _firstRowIndex = row; + store.dispatch(UpdateLastHistory( + (row / state.prefState.rowsPerPage).floor())); + }, initialFirstRowIndex: _firstRowIndex, availableRowsPerPage: [ 10, diff --git a/stubs/redux/stub/stub_actions b/stubs/redux/stub/stub_actions index ae829500d..d53b01b17 100644 --- a/stubs/redux/stub/stub_actions +++ b/stubs/redux/stub/stub_actions @@ -12,9 +12,11 @@ import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart' class ViewStubList implements PersistUI { ViewStubList({ this.force = false + this.page = 0, }); final bool force; + final int page; } class ViewStub