diff --git a/lib/data/models/serializers.g.dart b/lib/data/models/serializers.g.dart index 4faaffde3..2685d145d 100644 --- a/lib/data/models/serializers.g.dart +++ b/lib/data/models/serializers.g.dart @@ -17,7 +17,7 @@ Serializers _$serializers = (new Serializers().toBuilder() ..add(ClientState.serializer) ..add(ClientUIState.serializer) ..add(CompanyEntity.serializer) - ..add(CompanyState.serializer) + ..add(UserCompanyState.serializer) ..add(ContactEntity.serializer) ..add(CountryEntity.serializer) ..add(CountryItemResponse.serializer) diff --git a/lib/data/repositories/persistence_repository.dart b/lib/data/repositories/persistence_repository.dart index 74630c286..9fa55881f 100644 --- a/lib/data/repositories/persistence_repository.dart +++ b/lib/data/repositories/persistence_repository.dart @@ -20,22 +20,22 @@ class PersistenceRepository { final FileStorage fileStorage; - Future saveCompanyState(CompanyState state) async { + Future saveCompanyState(UserCompanyState state) async { /* // TODO re-enable final stateWithoutToken = state.rebuild( (b) => b..company.replace(state.company.rebuild((b) => b..token = ''))); */ - final data = serializers.serializeWith(CompanyState.serializer, state); + final data = serializers.serializeWith(UserCompanyState.serializer, state); return await fileStorage.save(json.encode(data)); } - Future loadCompanyState(int index) async { + Future loadCompanyState(int index) async { final String data = await fileStorage.load(); final SharedPreferences prefs = await SharedPreferences.getInstance(); final token = prefs.getString(getCompanyTokenKey(index - 1)) ?? ''; - final companyState = - serializers.deserializeWith(CompanyState.serializer, json.decode(data)); + final companyState = serializers.deserializeWith( + UserCompanyState.serializer, json.decode(data)); /* // TODO re-enable diff --git a/lib/redux/app/app_middleware.dart b/lib/redux/app/app_middleware.dart index 536b16d95..1c172de5a 100644 --- a/lib/redux/app/app_middleware.dart +++ b/lib/redux/app/app_middleware.dart @@ -143,11 +143,11 @@ Middleware _createLoadState( AuthState authState; UIState uiState; StaticState staticState; - CompanyState company1State; - CompanyState company2State; - CompanyState company3State; - CompanyState company4State; - CompanyState company5State; + UserCompanyState company1State; + UserCompanyState company2State; + UserCompanyState company3State; + UserCompanyState company4State; + UserCompanyState company5State; return (Store store, dynamic dynamicAction, NextDispatcher next) async { diff --git a/lib/redux/app/app_state.dart b/lib/redux/app/app_state.dart index d56faf22e..c9039a12a 100644 --- a/lib/redux/app/app_state.dart +++ b/lib/redux/app/app_state.dart @@ -49,13 +49,11 @@ abstract class AppState implements Built { serverVersion: '', authState: AuthState(), staticState: StaticState(), - /* - companyState1: CompanyState(), - companyState2: CompanyState(), - companyState3: CompanyState(), - companyState4: CompanyState(), - companyState5: CompanyState(), - */ + companyState1: UserCompanyState(), + companyState2: UserCompanyState(), + companyState3: UserCompanyState(), + companyState4: UserCompanyState(), + companyState5: UserCompanyState(), uiState: UIState( CompanyEntity(), enableDarkMode: enableDarkMode, @@ -80,20 +78,20 @@ abstract class AppState implements Built { UIState get uiState; - CompanyState get companyState1; + UserCompanyState get companyState1; - CompanyState get companyState2; + UserCompanyState get companyState2; - CompanyState get companyState3; + UserCompanyState get companyState3; - CompanyState get companyState4; + UserCompanyState get companyState4; - CompanyState get companyState5; + UserCompanyState get companyState5; //factory AppState([void updates(AppStateBuilder b)]) = _$AppState; static Serializer get serializer => _$appStateSerializer; - CompanyState get selectedCompanyState { + UserCompanyState get selectedCompanyState { switch (uiState.selectedCompanyIndex) { case 1: return companyState1; diff --git a/lib/redux/app/app_state.g.dart b/lib/redux/app/app_state.g.dart index a725cdef0..762353920 100644 --- a/lib/redux/app/app_state.g.dart +++ b/lib/redux/app/app_state.g.dart @@ -38,19 +38,19 @@ class _$AppStateSerializer implements StructuredSerializer { specifiedType: const FullType(UIState)), 'companyState1', serializers.serialize(object.companyState1, - specifiedType: const FullType(CompanyState)), + specifiedType: const FullType(UserCompanyState)), 'companyState2', serializers.serialize(object.companyState2, - specifiedType: const FullType(CompanyState)), + specifiedType: const FullType(UserCompanyState)), 'companyState3', serializers.serialize(object.companyState3, - specifiedType: const FullType(CompanyState)), + specifiedType: const FullType(UserCompanyState)), 'companyState4', serializers.serialize(object.companyState4, - specifiedType: const FullType(CompanyState)), + specifiedType: const FullType(UserCompanyState)), 'companyState5', serializers.serialize(object.companyState5, - specifiedType: const FullType(CompanyState)), + specifiedType: const FullType(UserCompanyState)), ]; return result; @@ -93,23 +93,28 @@ class _$AppStateSerializer implements StructuredSerializer { break; case 'companyState1': result.companyState1.replace(serializers.deserialize(value, - specifiedType: const FullType(CompanyState)) as CompanyState); + specifiedType: const FullType(UserCompanyState)) + as UserCompanyState); break; case 'companyState2': result.companyState2.replace(serializers.deserialize(value, - specifiedType: const FullType(CompanyState)) as CompanyState); + specifiedType: const FullType(UserCompanyState)) + as UserCompanyState); break; case 'companyState3': result.companyState3.replace(serializers.deserialize(value, - specifiedType: const FullType(CompanyState)) as CompanyState); + specifiedType: const FullType(UserCompanyState)) + as UserCompanyState); break; case 'companyState4': result.companyState4.replace(serializers.deserialize(value, - specifiedType: const FullType(CompanyState)) as CompanyState); + specifiedType: const FullType(UserCompanyState)) + as UserCompanyState); break; case 'companyState5': result.companyState5.replace(serializers.deserialize(value, - specifiedType: const FullType(CompanyState)) as CompanyState); + specifiedType: const FullType(UserCompanyState)) + as UserCompanyState); break; } } @@ -132,15 +137,15 @@ class _$AppState extends AppState { @override final UIState uiState; @override - final CompanyState companyState1; + final UserCompanyState companyState1; @override - final CompanyState companyState2; + final UserCompanyState companyState2; @override - final CompanyState companyState3; + final UserCompanyState companyState3; @override - final CompanyState companyState4; + final UserCompanyState companyState4; @override - final CompanyState companyState5; + final UserCompanyState companyState5; factory _$AppState([void Function(AppStateBuilder) updates]) => (new AppStateBuilder()..update(updates)).build(); diff --git a/lib/redux/company/company_reducer.dart b/lib/redux/company/company_reducer.dart index 09318abc4..eed4ebe8b 100644 --- a/lib/redux/company/company_reducer.dart +++ b/lib/redux/company/company_reducer.dart @@ -16,9 +16,9 @@ import 'package:invoiceninja_flutter/redux/payment/payment_reducer.dart'; import 'package:invoiceninja_flutter/redux/quote/quote_reducer.dart'; // STARTER: import - do not remove comment -CompanyState companyReducer(CompanyState state, dynamic action) { +UserCompanyState companyReducer(UserCompanyState state, dynamic action) { if (action is RefreshData && action.loadCompanies) { - return CompanyState(); + return UserCompanyState(); } return state.rebuild((b) => b diff --git a/lib/redux/company/company_selectors.dart b/lib/redux/company/company_selectors.dart index 8fef6b077..85d017fd5 100644 --- a/lib/redux/company/company_selectors.dart +++ b/lib/redux/company/company_selectors.dart @@ -54,9 +54,9 @@ List getCurrencyIds( } var memoizedFilteredSelector = memo2( - (String filter, CompanyState state) => filteredSelector(filter, state)); + (String filter, UserCompanyState state) => filteredSelector(filter, state)); -List filteredSelector(String filter, CompanyState state) { +List filteredSelector(String filter, UserCompanyState state) { final List list = [] ..addAll(state.productState.list .map((productId) => state.productState.map[productId]) diff --git a/lib/redux/company/company_state.dart b/lib/redux/company/company_state.dart index 7049442ff..120d580db 100644 --- a/lib/redux/company/company_state.dart +++ b/lib/redux/company/company_state.dart @@ -23,9 +23,9 @@ import 'package:invoiceninja_flutter/redux/quote/quote_state.dart'; part 'company_state.g.dart'; -abstract class CompanyState - implements Built { - factory CompanyState() { +abstract class UserCompanyState + implements Built { + factory UserCompanyState() { return _$CompanyState._( userCompany: UserCompanyEntity(), documentState: DocumentState(), @@ -43,7 +43,7 @@ abstract class CompanyState ); } - CompanyState._(); + UserCompanyState._(); @nullable UserCompanyEntity get userCompany; @@ -79,5 +79,6 @@ abstract class CompanyState TokenEntity get token => userCompany.token; //factory CompanyState([void updates(CompanyStateBuilder b)]) = _$CompanyState; - static Serializer get serializer => _$companyStateSerializer; + static Serializer get serializer => + _$companyStateSerializer; } diff --git a/lib/redux/company/company_state.g.dart b/lib/redux/company/company_state.g.dart index a5dfff0da..d7afc00a7 100644 --- a/lib/redux/company/company_state.g.dart +++ b/lib/redux/company/company_state.g.dart @@ -6,17 +6,18 @@ part of 'company_state.dart'; // BuiltValueGenerator // ************************************************************************** -Serializer _$companyStateSerializer = +Serializer _$companyStateSerializer = new _$CompanyStateSerializer(); -class _$CompanyStateSerializer implements StructuredSerializer { +class _$CompanyStateSerializer + implements StructuredSerializer { @override - final Iterable types = const [CompanyState, _$CompanyState]; + final Iterable types = const [UserCompanyState, _$CompanyState]; @override final String wireName = 'CompanyState'; @override - Iterable serialize(Serializers serializers, CompanyState object, + Iterable serialize(Serializers serializers, UserCompanyState object, {FullType specifiedType = FullType.unspecified}) { final result = [ 'documentState', @@ -63,7 +64,8 @@ class _$CompanyStateSerializer implements StructuredSerializer { } @override - CompanyState deserialize(Serializers serializers, Iterable serialized, + UserCompanyState deserialize( + Serializers serializers, Iterable serialized, {FullType specifiedType = FullType.unspecified}) { final result = new CompanyStateBuilder(); @@ -129,7 +131,7 @@ class _$CompanyStateSerializer implements StructuredSerializer { } } -class _$CompanyState extends CompanyState { +class _$CompanyState extends UserCompanyState { @override final UserCompanyEntity userCompany; @override @@ -208,7 +210,7 @@ class _$CompanyState extends CompanyState { } @override - CompanyState rebuild(void Function(CompanyStateBuilder) updates) => + UserCompanyState rebuild(void Function(CompanyStateBuilder) updates) => (toBuilder()..update(updates)).build(); @override @@ -217,7 +219,7 @@ class _$CompanyState extends CompanyState { @override bool operator ==(Object other) { if (identical(other, this)) return true; - return other is CompanyState && + return other is UserCompanyState && userCompany == other.userCompany && documentState == other.documentState && dashboardState == other.dashboardState && @@ -278,7 +280,7 @@ class _$CompanyState extends CompanyState { } class CompanyStateBuilder - implements Builder { + implements Builder { _$CompanyState _$v; UserCompanyEntityBuilder _userCompany; @@ -374,7 +376,7 @@ class CompanyStateBuilder } @override - void replace(CompanyState other) { + void replace(UserCompanyState other) { if (other == null) { throw new ArgumentError.notNull('other'); }