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