From f9c23176cc64fed9945d7a962ec2b4cd37e1092b Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 3 Jun 2019 12:55:39 +0300 Subject: [PATCH] Vendors --- lib/redux/vendor/vendor_actions.dart | 9 ++++++--- lib/redux/vendor/vendor_reducer.dart | 27 +++++++++++++++++++++++++++ pubspec.yaml | 2 +- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/lib/redux/vendor/vendor_actions.dart b/lib/redux/vendor/vendor_actions.dart index 5760b8b10..1425faab2 100644 --- a/lib/redux/vendor/vendor_actions.dart +++ b/lib/redux/vendor/vendor_actions.dart @@ -19,9 +19,14 @@ class ViewVendor implements PersistUI { class EditVendor implements PersistUI { EditVendor( - {this.vendor, this.context, this.completer, this.trackRoute = true}); + {this.vendor, + this.contact, + this.context, + this.completer, + this.trackRoute = true}); final VendorEntity vendor; + final VendorContactEntity contact; final BuildContext context; final Completer completer; final bool trackRoute; @@ -185,7 +190,6 @@ class RestoreVendorFailure implements StopSaving { final VendorEntity vendor; } - class EditVendorContact implements PersistUI { EditVendorContact([this.contact]); @@ -211,7 +215,6 @@ class DeleteVendorContact implements PersistUI { final int index; } - class FilterVendors { FilterVendors(this.filter); diff --git a/lib/redux/vendor/vendor_reducer.dart b/lib/redux/vendor/vendor_reducer.dart index 753f18c4a..727096e9d 100644 --- a/lib/redux/vendor/vendor_reducer.dart +++ b/lib/redux/vendor/vendor_reducer.dart @@ -10,9 +10,20 @@ EntityUIState vendorUIReducer(VendorUIState state, dynamic action) { return state.rebuild((b) => b ..listUIState.replace(vendorListReducer(state.listUIState, action)) ..editing.replace(editingReducer(state.editing, action)) + ..editingContact + .replace(editingVendorContactReducer(state.editingContact, action)) ..selectedId = selectedIdReducer(state.selectedId, action)); } +final editingVendorContactReducer = combineReducers([ + TypedReducer(editVendorContact), + TypedReducer(editVendorContact), +]); + +VendorContactEntity editVendorContact(VendorContactEntity contact, dynamic action) { + return action.contact ?? VendorContactEntity(); +} + Reducer selectedIdReducer = combineReducers([ TypedReducer( (int selectedId, dynamic action) => action.vendorId), @@ -28,6 +39,9 @@ final editingReducer = combineReducers([ TypedReducer(_updateEditing), TypedReducer(_updateEditing), TypedReducer(_updateEditing), + TypedReducer(_addContact), + TypedReducer(_removeContact), + TypedReducer(_updateContact), TypedReducer(_clearEditing), ]); @@ -39,6 +53,19 @@ VendorEntity _updateEditing(VendorEntity vendor, dynamic action) { return action.vendor; } +VendorEntity _addContact(VendorEntity vendor, AddVendorContact action) { + return vendor + .rebuild((b) => b..contacts.add(action.contact ?? VendorContactEntity())); +} + +VendorEntity _removeContact(VendorEntity vendor, DeleteVendorContact action) { + return vendor.rebuild((b) => b..contacts.removeAt(action.index)); +} + +VendorEntity _updateContact(VendorEntity vendor, UpdateVendorContact action) { + return vendor.rebuild((b) => b..contacts[action.index] = action.contact); +} + final vendorListReducer = combineReducers([ TypedReducer(_sortVendors), TypedReducer(_filterVendorsByState), diff --git a/pubspec.yaml b/pubspec.yaml index 82021ef99..6a34ebb63 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: invoiceninja_flutter description: Mobile app for Invoice Ninja -version: 0.1.41 +version: 0.1.42 author: Hillel Coren homepage: https://www.invoiceninja.com documentation: http://docs.invoiceninja.com