Login...
This commit is contained in:
parent
2d8cef62d0
commit
3aad3b385e
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -20,22 +20,22 @@ class PersistenceRepository {
|
|||
|
||||
final FileStorage fileStorage;
|
||||
|
||||
Future<File> saveCompanyState(CompanyState state) async {
|
||||
Future<File> 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<CompanyState> loadCompanyState(int index) async {
|
||||
Future<UserCompanyState> 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
|
||||
|
|
|
|||
|
|
@ -143,11 +143,11 @@ Middleware<AppState> _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<AppState> store, dynamic dynamicAction,
|
||||
NextDispatcher next) async {
|
||||
|
|
|
|||
|
|
@ -49,13 +49,11 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
|||
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<AppState, AppStateBuilder> {
|
|||
|
||||
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<AppState> get serializer => _$appStateSerializer;
|
||||
|
||||
CompanyState get selectedCompanyState {
|
||||
UserCompanyState get selectedCompanyState {
|
||||
switch (uiState.selectedCompanyIndex) {
|
||||
case 1:
|
||||
return companyState1;
|
||||
|
|
|
|||
|
|
@ -38,19 +38,19 @@ class _$AppStateSerializer implements StructuredSerializer<AppState> {
|
|||
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<AppState> {
|
|||
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();
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ List<String> getCurrencyIds(
|
|||
}
|
||||
|
||||
var memoizedFilteredSelector = memo2(
|
||||
(String filter, CompanyState state) => filteredSelector(filter, state));
|
||||
(String filter, UserCompanyState state) => filteredSelector(filter, state));
|
||||
|
||||
List<BaseEntity> filteredSelector(String filter, CompanyState state) {
|
||||
List<BaseEntity> filteredSelector(String filter, UserCompanyState state) {
|
||||
final List<BaseEntity> list = []
|
||||
..addAll(state.productState.list
|
||||
.map((productId) => state.productState.map[productId])
|
||||
|
|
|
|||
|
|
@ -23,9 +23,9 @@ import 'package:invoiceninja_flutter/redux/quote/quote_state.dart';
|
|||
|
||||
part 'company_state.g.dart';
|
||||
|
||||
abstract class CompanyState
|
||||
implements Built<CompanyState, CompanyStateBuilder> {
|
||||
factory CompanyState() {
|
||||
abstract class UserCompanyState
|
||||
implements Built<UserCompanyState, CompanyStateBuilder> {
|
||||
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<CompanyState> get serializer => _$companyStateSerializer;
|
||||
static Serializer<UserCompanyState> get serializer =>
|
||||
_$companyStateSerializer;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,17 +6,18 @@ part of 'company_state.dart';
|
|||
// BuiltValueGenerator
|
||||
// **************************************************************************
|
||||
|
||||
Serializer<CompanyState> _$companyStateSerializer =
|
||||
Serializer<UserCompanyState> _$companyStateSerializer =
|
||||
new _$CompanyStateSerializer();
|
||||
|
||||
class _$CompanyStateSerializer implements StructuredSerializer<CompanyState> {
|
||||
class _$CompanyStateSerializer
|
||||
implements StructuredSerializer<UserCompanyState> {
|
||||
@override
|
||||
final Iterable<Type> types = const [CompanyState, _$CompanyState];
|
||||
final Iterable<Type> types = const [UserCompanyState, _$CompanyState];
|
||||
@override
|
||||
final String wireName = 'CompanyState';
|
||||
|
||||
@override
|
||||
Iterable<Object> serialize(Serializers serializers, CompanyState object,
|
||||
Iterable<Object> serialize(Serializers serializers, UserCompanyState object,
|
||||
{FullType specifiedType = FullType.unspecified}) {
|
||||
final result = <Object>[
|
||||
'documentState',
|
||||
|
|
@ -63,7 +64,8 @@ class _$CompanyStateSerializer implements StructuredSerializer<CompanyState> {
|
|||
}
|
||||
|
||||
@override
|
||||
CompanyState deserialize(Serializers serializers, Iterable<Object> serialized,
|
||||
UserCompanyState deserialize(
|
||||
Serializers serializers, Iterable<Object> serialized,
|
||||
{FullType specifiedType = FullType.unspecified}) {
|
||||
final result = new CompanyStateBuilder();
|
||||
|
||||
|
|
@ -129,7 +131,7 @@ class _$CompanyStateSerializer implements StructuredSerializer<CompanyState> {
|
|||
}
|
||||
}
|
||||
|
||||
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<CompanyState, CompanyStateBuilder> {
|
||||
implements Builder<UserCompanyState, CompanyStateBuilder> {
|
||||
_$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');
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue