diff --git a/lib/redux/ui/ui_state.dart b/lib/redux/ui/ui_state.dart index 9dc2ae964..af7d0c673 100644 --- a/lib/redux/ui/ui_state.dart +++ b/lib/redux/ui/ui_state.dart @@ -74,4 +74,6 @@ ProjectUIState get projectUIState; QuoteUIState get quoteUIState; static Serializer get serializer => _$uIStateSerializer; + + bool containsRoute(String route) => currentRoute.contains(route); } diff --git a/lib/ui/client/edit/client_edit_vm.dart b/lib/ui/client/edit/client_edit_vm.dart index 6c712d6ae..87a75130b 100644 --- a/lib/ui/client/edit/client_edit_vm.dart +++ b/lib/ui/client/edit/client_edit_vm.dart @@ -60,8 +60,11 @@ class ClientEditVM { origClient: state.clientState.map[client.id], staticState: state.staticState, isSaving: state.isSaving, - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(ClientScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(ClientScreen.route)) { + store.dispatch(UpdateCurrentRoute(ClientViewScreen.route)); + } + }, onChanged: (ClientEntity client) => store.dispatch(UpdateClient(client)), onSavePressed: (BuildContext context) { diff --git a/lib/ui/client/view/client_view_vm.dart b/lib/ui/client/view/client_view_vm.dart index 468c4f1b0..53882c903 100644 --- a/lib/ui/client/view/client_view_vm.dart +++ b/lib/ui/client/view/client_view_vm.dart @@ -109,8 +109,11 @@ class ClientViewVM { }, onRefreshed: (context, loadActivities) => _handleRefresh(context, loadActivities), - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(ClientScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(ClientScreen.route)) { + store.dispatch(UpdateCurrentRoute(ClientScreen.route)); + } + }, onActionSelected: (BuildContext context, EntityAction action) { final localization = AppLocalization.of(context); switch (action) { diff --git a/lib/ui/invoice/edit/invoice_edit_vm.dart b/lib/ui/invoice/edit/invoice_edit_vm.dart index ea77c3d68..d14cdedb5 100644 --- a/lib/ui/invoice/edit/invoice_edit_vm.dart +++ b/lib/ui/invoice/edit/invoice_edit_vm.dart @@ -85,8 +85,11 @@ class InvoiceEditVM extends EntityEditVM { invoice: invoice, invoiceItem: state.invoiceUIState.editingItem, origInvoice: store.state.invoiceState.map[invoice.id], - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(InvoiceScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(InvoiceScreen.route)) { + store.dispatch(UpdateCurrentRoute(InvoiceViewScreen.route)); + } + }, onSavePressed: (BuildContext context) { final Completer completer = Completer(); store.dispatch( diff --git a/lib/ui/invoice/view/invoice_view_vm.dart b/lib/ui/invoice/view/invoice_view_vm.dart index fd47c04a0..319150c0e 100644 --- a/lib/ui/invoice/view/invoice_view_vm.dart +++ b/lib/ui/invoice/view/invoice_view_vm.dart @@ -149,8 +149,11 @@ class InvoiceViewVM extends EntityViewVM { }); }, onRefreshed: (context) => _handleRefresh(context), - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(InvoiceScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(InvoiceScreen.route)) { + store.dispatch(UpdateCurrentRoute(InvoiceScreen.route)); + } + }, onClientPressed: (BuildContext context) => store.dispatch(ViewClient(clientId: client.id, context: context)), onPaymentPressed: (BuildContext context, PaymentEntity payment) => store diff --git a/lib/ui/payment/edit/payment_edit_vm.dart b/lib/ui/payment/edit/payment_edit_vm.dart index a6b82a229..975383c99 100644 --- a/lib/ui/payment/edit/payment_edit_vm.dart +++ b/lib/ui/payment/edit/payment_edit_vm.dart @@ -83,7 +83,9 @@ class PaymentEditVM { store.dispatch(UserSettingsChanged(emailPayment: value)); }, onBackPressed: () { - store.dispatch(UpdateCurrentRoute(PaymentScreen.route)); + if (state.uiState.currentRoute.contains(PaymentScreen.route)) { + store.dispatch(UpdateCurrentRoute(PaymentViewScreen.route)); + } }, onSavePressed: (BuildContext context) { final Completer completer = errorCompleter(context) diff --git a/lib/ui/product/edit/product_edit_vm.dart b/lib/ui/product/edit/product_edit_vm.dart index 44d273353..675bebd69 100644 --- a/lib/ui/product/edit/product_edit_vm.dart +++ b/lib/ui/product/edit/product_edit_vm.dart @@ -58,7 +58,9 @@ class ProductEditVM { store.dispatch(UpdateProduct(product)); }, onBackPressed: () { - store.dispatch(UpdateCurrentRoute(ProductScreen.route)); + if (state.uiState.currentRoute.contains(ProductScreen.route)) { + store.dispatch(UpdateCurrentRoute(ProductScreen.route)); + } }, onSavePressed: (BuildContext context) { store.dispatch(SaveProductRequest( diff --git a/lib/ui/project/edit/project_edit_vm.dart b/lib/ui/project/edit/project_edit_vm.dart index 9fe09e4b3..070b00feb 100644 --- a/lib/ui/project/edit/project_edit_vm.dart +++ b/lib/ui/project/edit/project_edit_vm.dart @@ -68,7 +68,9 @@ class ProjectEditVM { store.dispatch(UpdateProject(project)); }, onBackPressed: () { - store.dispatch(UpdateCurrentRoute(ProjectScreen.route)); + if (state.uiState.currentRoute.contains(ProjectScreen.route)) { + store.dispatch(UpdateCurrentRoute(ProjectViewScreen.route)); + } }, onAddClientPressed: (context, completer) { store.dispatch(EditClient( diff --git a/lib/ui/project/view/project_view_vm.dart b/lib/ui/project/view/project_view_vm.dart index 4b1c1dae3..7e3c8ad20 100644 --- a/lib/ui/project/view/project_view_vm.dart +++ b/lib/ui/project/view/project_view_vm.dart @@ -71,8 +71,11 @@ class ProjectViewVM { onRefreshed: (context) => _handleRefresh(context), onClientPressed: (BuildContext context) => store .dispatch(ViewClient(clientId: project.clientId, context: context)), - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(ProjectScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(ProjectScreen.route)) { + store.dispatch(UpdateCurrentRoute(ProjectScreen.route)); + } + }, onActionSelected: (BuildContext context, EntityAction action) { final localization = AppLocalization.of(context); switch (action) { diff --git a/lib/ui/quote/edit/quote_edit_vm.dart b/lib/ui/quote/edit/quote_edit_vm.dart index 4edbacf0c..bbad472df 100644 --- a/lib/ui/quote/edit/quote_edit_vm.dart +++ b/lib/ui/quote/edit/quote_edit_vm.dart @@ -64,8 +64,11 @@ class QuoteEditVM extends EntityEditVM { invoice: quote, invoiceItem: state.quoteUIState.editingItem, origInvoice: store.state.quoteState.map[quote.id], - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(QuoteScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(QuoteScreen.route)) { + store.dispatch(UpdateCurrentRoute(QuoteViewScreen.route)); + } + }, onSavePressed: (BuildContext context) { final Completer completer = Completer(); store.dispatch(SaveQuoteRequest(completer: completer, quote: quote)); diff --git a/lib/ui/quote/view/quote_view_vm.dart b/lib/ui/quote/view/quote_view_vm.dart index 20fe0f903..7f713235b 100644 --- a/lib/ui/quote/view/quote_view_vm.dart +++ b/lib/ui/quote/view/quote_view_vm.dart @@ -102,8 +102,11 @@ class QuoteViewVM extends EntityViewVM { }); }, onRefreshed: (context) => _handleRefresh(context), - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(QuoteScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(QuoteScreen.route)) { + store.dispatch(UpdateCurrentRoute(QuoteScreen.route)); + } + }, onClientPressed: (BuildContext context) { store.dispatch(ViewClient(clientId: client.id, context: context)); }, diff --git a/lib/ui/task/edit/task_edit_vm.dart b/lib/ui/task/edit/task_edit_vm.dart index 800f4d433..3b0dceb68 100644 --- a/lib/ui/task/edit/task_edit_vm.dart +++ b/lib/ui/task/edit/task_edit_vm.dart @@ -66,7 +66,9 @@ class TaskEditVM { store.dispatch(UpdateTask(task)); }, onBackPressed: () { - store.dispatch(UpdateCurrentRoute(TaskScreen.route)); + if (state.uiState.currentRoute.contains(TaskScreen.route)) { + store.dispatch(UpdateCurrentRoute(TaskScreen.route)); + } }, onAddClientPressed: (context, completer) { store.dispatch(EditClient( diff --git a/lib/ui/task/view/task_view_vm.dart b/lib/ui/task/view/task_view_vm.dart index 59bfd2f68..b35a742c0 100644 --- a/lib/ui/task/view/task_view_vm.dart +++ b/lib/ui/task/view/task_view_vm.dart @@ -66,8 +66,11 @@ class TaskViewVM { store.dispatch(EditTask(task: task, context: context)); }, onRefreshed: (context) => _handleRefresh(context), - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(TaskScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(TaskScreen.route)) { + store.dispatch(UpdateCurrentRoute(TaskScreen.route)); + } + }, onActionSelected: (BuildContext context, EntityAction action) { final localization = AppLocalization.of(context); switch (action) { diff --git a/stubs/ui/stub/edit/stub_edit_vm b/stubs/ui/stub/edit/stub_edit_vm index 2ceb47daa..b965db800 100644 --- a/stubs/ui/stub/edit/stub_edit_vm +++ b/stubs/ui/stub/edit/stub_edit_vm @@ -60,7 +60,9 @@ class StubEditVM { store.dispatch(UpdateStub(stub)); }, onBackPressed: () { - store.dispatch(UpdateCurrentRoute(StubScreen.route)); + if (state.uiState.currentRoute.contains(StubScreen.route)) { + store.dispatch(UpdateCurrentRoute(StubViewScreen.route)); + } }, onSavePressed: (BuildContext context) { final Completer completer = new Completer(); diff --git a/stubs/ui/stub/view/stub_view_vm b/stubs/ui/stub/view/stub_view_vm index 6357b5f4f..a9e4869fa 100644 --- a/stubs/ui/stub/view/stub_view_vm +++ b/stubs/ui/stub/view/stub_view_vm @@ -66,8 +66,11 @@ class StubViewVM { store.dispatch(EditStub(stub: stub, context: context)); }, onRefreshed: (context) => _handleRefresh(context), - onBackPressed: () => - store.dispatch(UpdateCurrentRoute(StubScreen.route)), + onBackPressed: () { + if (state.uiState.currentRoute.contains(StubScreen.route)) { + store.dispatch(UpdateCurrentRoute(StubScreen.route)); + } + }, onActionSelected: (BuildContext context, EntityAction action) { final localization = AppLocalization.of(context); switch (action) {