Code refactor
This commit is contained in:
parent
56a1a06fbf
commit
5cf79dd953
|
|
@ -186,9 +186,6 @@ Serializers _$serializers = (new Serializers().toBuilder()
|
|||
const FullType(
|
||||
BuiltList, const [const FullType(CompanyGatewayEntity)]),
|
||||
() => new ListBuilder<CompanyGatewayEntity>())
|
||||
..addBuilderFactory(
|
||||
const FullType(BuiltList, const [const FullType(CompanyPrefState)]),
|
||||
() => new ListBuilder<CompanyPrefState>())
|
||||
..addBuilderFactory(
|
||||
const FullType(BuiltList, const [const FullType(ContactEntity)]),
|
||||
() => new ListBuilder<ContactEntity>())
|
||||
|
|
@ -435,6 +432,7 @@ Serializers _$serializers = (new Serializers().toBuilder()
|
|||
..addBuilderFactory(const FullType(BuiltList, const [const FullType(String)]), () => new ListBuilder<String>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(CompanyGatewayEntity)]), () => new MapBuilder<String, CompanyGatewayEntity>())
|
||||
..addBuilderFactory(const FullType(BuiltList, const [const FullType(String)]), () => new ListBuilder<String>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(CompanyPrefState)]), () => new MapBuilder<String, CompanyPrefState>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(CurrencyEntity)]), () => new MapBuilder<String, CurrencyEntity>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(SizeEntity)]), () => new MapBuilder<String, SizeEntity>())
|
||||
..addBuilderFactory(const FullType(BuiltMap, const [const FullType(String), const FullType(GatewayEntity)]), () => new MapBuilder<String, GatewayEntity>())
|
||||
|
|
|
|||
|
|
@ -58,7 +58,7 @@ AppState appReducer(AppState state, dynamic action) {
|
|||
state.userCompanyStates[state.uiState.selectedCompanyIndex], action)
|
||||
..uiState.replace(uiReducer(state.uiState, action))
|
||||
..prefState.replace(prefReducer(
|
||||
state.prefState, action, state.uiState.selectedCompanyIndex)));
|
||||
state.prefState, action, state.company.id)));
|
||||
}
|
||||
|
||||
final lastErrorReducer = combineReducers<String>([
|
||||
|
|
|
|||
|
|
@ -166,8 +166,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
|||
'${account?.currentVersion ?? '0.0.0'}-${kClientVersion.split('.').last}';
|
||||
|
||||
List<HistoryRecord> get historyList =>
|
||||
prefState.companyPrefs[uiState.selectedCompanyIndex].historyList
|
||||
.where((history) {
|
||||
prefState.companyPrefs[company.id].historyList.where((history) {
|
||||
final entityMap = getEntityMap(history.entityType);
|
||||
if (entityMap != null) {
|
||||
final entity = entityMap[history.id] as BaseEntity;
|
||||
|
|
@ -179,7 +178,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
|||
}).toList();
|
||||
|
||||
List<HistoryRecord> get unfilteredHistoryList =>
|
||||
prefState.companyPrefs[uiState.selectedCompanyIndex].historyList.toList();
|
||||
prefState.companyPrefs[company.id].historyList.toList();
|
||||
|
||||
bool shouldSelectEntity({EntityType entityType, List<String> entityList}) {
|
||||
final entityUIState = getUIState(entityType);
|
||||
|
|
|
|||
|
|
@ -37,11 +37,11 @@ import 'package:invoiceninja_flutter/redux/credit/credit_actions.dart';
|
|||
import 'package:redux/redux.dart';
|
||||
|
||||
PrefState prefReducer(
|
||||
PrefState state, dynamic action, int selectedCompanyIndex) {
|
||||
PrefState state, dynamic action, String selectedCompanyId) {
|
||||
return state.rebuild(
|
||||
(b) => b
|
||||
..companyPrefs[selectedCompanyIndex] =
|
||||
companyPrefReducer(state.companyPrefs[selectedCompanyIndex], action)
|
||||
..companyPrefs[selectedCompanyId] =
|
||||
companyPrefReducer(state.companyPrefs[selectedCompanyId], action)
|
||||
..appLayout = layoutReducer(state.appLayout, action)
|
||||
..rowsPerPage = rowsPerPageReducer(state.rowsPerPage, action)
|
||||
..moduleLayout = moduleLayoutReducer(state.moduleLayout, action)
|
||||
|
|
@ -299,6 +299,8 @@ Reducer<SettingsUIState> settingsUIReducer = combineReducers([
|
|||
]);
|
||||
|
||||
CompanyPrefState companyPrefReducer(CompanyPrefState state, dynamic action) {
|
||||
state ??= CompanyPrefState();
|
||||
|
||||
return state.rebuild(
|
||||
(b) => b..historyList.replace(historyReducer(state.historyList, action)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@ import 'package:built_collection/built_collection.dart';
|
|||
import 'package:built_value/built_value.dart';
|
||||
import 'package:built_value/serializer.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:invoiceninja_flutter/constants.dart';
|
||||
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
||||
|
||||
part 'pref_state.g.dart';
|
||||
|
|
@ -24,11 +23,7 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
|
|||
showFilterSidebar: false,
|
||||
longPressSelectionIsDefault: false,
|
||||
addDocumentsToInvoice: false,
|
||||
companyPrefs: BuiltList(
|
||||
List<int>.generate(kMaxNumberOfCompanies, (i) => i + 1)
|
||||
.map((index) => CompanyPrefState())
|
||||
.toList(),
|
||||
),
|
||||
companyPrefs: BuiltMap<String, CompanyPrefState>(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -66,7 +61,7 @@ abstract class PrefState implements Built<PrefState, PrefStateBuilder> {
|
|||
|
||||
int get rowsPerPage;
|
||||
|
||||
BuiltList<CompanyPrefState> get companyPrefs;
|
||||
BuiltMap<String, CompanyPrefState> get companyPrefs;
|
||||
|
||||
bool get isDesktop => appLayout == AppLayout.desktop;
|
||||
|
||||
|
|
|
|||
|
|
@ -155,8 +155,10 @@ class _$PrefStateSerializer implements StructuredSerializer<PrefState> {
|
|||
specifiedType: const FullType(int)),
|
||||
'companyPrefs',
|
||||
serializers.serialize(object.companyPrefs,
|
||||
specifiedType: const FullType(
|
||||
BuiltList, const [const FullType(CompanyPrefState)])),
|
||||
specifiedType: const FullType(BuiltMap, const [
|
||||
const FullType(String),
|
||||
const FullType(CompanyPrefState)
|
||||
])),
|
||||
];
|
||||
|
||||
return result;
|
||||
|
|
@ -231,9 +233,10 @@ class _$PrefStateSerializer implements StructuredSerializer<PrefState> {
|
|||
break;
|
||||
case 'companyPrefs':
|
||||
result.companyPrefs.replace(serializers.deserialize(value,
|
||||
specifiedType: const FullType(
|
||||
BuiltList, const [const FullType(CompanyPrefState)]))
|
||||
as BuiltList<Object>);
|
||||
specifiedType: const FullType(BuiltMap, const [
|
||||
const FullType(String),
|
||||
const FullType(CompanyPrefState)
|
||||
])));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -443,7 +446,7 @@ class _$PrefState extends PrefState {
|
|||
@override
|
||||
final int rowsPerPage;
|
||||
@override
|
||||
final BuiltList<CompanyPrefState> companyPrefs;
|
||||
final BuiltMap<String, CompanyPrefState> companyPrefs;
|
||||
|
||||
factory _$PrefState([void Function(PrefStateBuilder) updates]) =>
|
||||
(new PrefStateBuilder()..update(updates)).build();
|
||||
|
|
@ -674,10 +677,10 @@ class PrefStateBuilder implements Builder<PrefState, PrefStateBuilder> {
|
|||
int get rowsPerPage => _$this._rowsPerPage;
|
||||
set rowsPerPage(int rowsPerPage) => _$this._rowsPerPage = rowsPerPage;
|
||||
|
||||
ListBuilder<CompanyPrefState> _companyPrefs;
|
||||
ListBuilder<CompanyPrefState> get companyPrefs =>
|
||||
_$this._companyPrefs ??= new ListBuilder<CompanyPrefState>();
|
||||
set companyPrefs(ListBuilder<CompanyPrefState> companyPrefs) =>
|
||||
MapBuilder<String, CompanyPrefState> _companyPrefs;
|
||||
MapBuilder<String, CompanyPrefState> get companyPrefs =>
|
||||
_$this._companyPrefs ??= new MapBuilder<String, CompanyPrefState>();
|
||||
set companyPrefs(MapBuilder<String, CompanyPrefState> companyPrefs) =>
|
||||
_$this._companyPrefs = companyPrefs;
|
||||
|
||||
PrefStateBuilder();
|
||||
|
|
|
|||
Loading…
Reference in New Issue