Code refactor

This commit is contained in:
Hillel Coren 2020-07-08 00:26:04 +03:00
parent f9661daeed
commit 3e9a67d1aa
25 changed files with 35 additions and 27 deletions

View File

@ -419,12 +419,14 @@ Middleware<AppState> _createAccountLoaded() {
final action = dynamicAction as LoadAccountSuccess;
final response = action.loginResponse;
final selectedCompanyIndex = store.state.uiState.selectedCompanyIndex;
final loadedStaticData = response.static.currencies.isNotEmpty;
if (response.static.currencies.isNotEmpty) {
if (loadedStaticData) {
store.dispatch(LoadStaticSuccess(data: response.static));
}
print('## userCompanies.length: ${response.userCompanies.length}');
for (int i = 0; i < response.userCompanies.length; i++) {
final UserCompanyEntity userCompany = response.userCompanies[i];
@ -433,11 +435,11 @@ Middleware<AppState> _createAccountLoaded() {
prefs.setString(kSharedPrefToken, userCompany.token.obscuredToken);
}
store.dispatch(SelectCompany(i));
store.dispatch(SelectCompany(companyIndex: i, clearSelection: loadedStaticData));
store.dispatch(LoadCompanySuccess(userCompany));
}
store.dispatch(SelectCompany(selectedCompanyIndex));
store.dispatch(SelectCompany(companyIndex: selectedCompanyIndex, clearSelection: loadedStaticData));
store.dispatch(UserLoginSuccess());
print('## Account is loaded');

View File

@ -270,7 +270,7 @@ Middleware<AppState> _createCompany(AuthRepository repository) {
store.dispatch(RefreshData(
completer: Completer<Null>()
..future.then<Null>((_) {
store.dispatch(SelectCompany(state.companies.length));
store.dispatch(SelectCompany(companyIndex: state.companies.length));
store.dispatch(ViewDashboard(
navigator: Navigator.of(action.context), force: true));
}),

View File

@ -49,7 +49,8 @@ final selectedIdReducer = combineReducers<String>([
TypedReducer<String, AddClientSuccess>((selectedId, action) {
return action.client.id;
}),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>(
(selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteClientsSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveClientsSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -6,9 +6,13 @@ import 'package:invoiceninja_flutter/data/models/company_model.dart';
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
class SelectCompany {
SelectCompany(this.companyIndex);
SelectCompany({
@required this.companyIndex,
this.clearSelection = true,
});
final int companyIndex;
final bool clearSelection;
}
class LoadCompanySuccess {
@ -44,6 +48,7 @@ class SaveCompanyFailure implements StopSaving {
class AddCompany implements StartSaving {
AddCompany(this.context);
final BuildContext context;
}

View File

@ -21,7 +21,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(String selectedId, action) => action.companyGatewayId),
TypedReducer<String, AddCompanyGatewaySuccess>(
(String selectedId, action) => action.companyGateway.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteCompanyGatewaySuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveCompanyGatewaySuccess>(
(selectedId, action) => ''),

View File

@ -37,7 +37,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(selectedId, action) => action.credit.id),
TypedReducer<String, ShowEmailCredit>(
(selectedId, action) => action.credit.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteCreditsSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveCreditsSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -20,7 +20,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(String selectedId, dynamic action) => action.designId),
TypedReducer<String, AddDesignSuccess>(
(String selectedId, dynamic action) => action.design.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteDesignsSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveDesignsSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -18,7 +18,7 @@ EntityUIState documentUIReducer(DocumentUIState state, dynamic action) {
Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, ViewDocument>((selectedId, action) => action.documentId),
//TypedReducer<String, AddDocumentSuccess>((selectedId, action) => action.document.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteDocumentSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveDocumentSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -19,7 +19,7 @@ Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, ViewExpense>((selectedId, action) => action.expenseId),
TypedReducer<String, AddExpenseSuccess>(
(selectedId, action) => action.expense.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteExpenseSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveExpenseSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -21,7 +21,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(String selectedId, action) => action.groupId),
TypedReducer<String, AddGroupSuccess>(
(String selectedId, action) => action.group.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteGroupSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveGroupSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -39,7 +39,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(selectedId, action) => action.invoice.id),
TypedReducer<String, ShowEmailInvoice>(
(selectedId, action) => action.invoice.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteInvoicesSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveInvoicesSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -19,7 +19,7 @@ Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, ViewPayment>((selectedId, action) => action.paymentId),
TypedReducer<String, AddPaymentSuccess>(
(selectedId, action) => action.payment.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeletePaymentsSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchivePaymentsSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -20,7 +20,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(String selectedId, dynamic action) => action.paymentTermId),
TypedReducer<String, AddPaymentTermSuccess>(
(String selectedId, dynamic action) => action.paymentTerm.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeletePaymentTermsSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchivePaymentTermsSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -56,7 +56,7 @@ Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, ViewProduct>((selectedId, action) => action.productId),
TypedReducer<String, AddProductSuccess>(
(selectedId, action) => action.product.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteProductsSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveProductsSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -35,7 +35,7 @@ Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, ViewProject>((selectedId, action) => action.projectId),
TypedReducer<String, AddProjectSuccess>(
(selectedId, action) => action.project.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteProjectSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveProjectSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -37,7 +37,7 @@ Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, AddQuoteSuccess>(
(selectedId, action) => action.quote.id),
TypedReducer<String, ShowEmailQuote>((selectedId, action) => action.quote.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteQuotesSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveQuotesSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -28,7 +28,7 @@ TaskTime editTaskTime(TaskTime taskTime, dynamic action) {
Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, ViewTask>((selectedId, action) => action.taskId),
TypedReducer<String, AddTaskSuccess>((selectedId, action) => action.task.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteTaskSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveTaskSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -20,7 +20,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(String selectedId, action) => action.taxRateId),
TypedReducer<String, AddTaxRateSuccess>(
(String selectedId, action) => action.taxRate.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteTaxRatesSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveTaxRatesSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -21,7 +21,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(String selectedId, dynamic action) => action.tokenId),
TypedReducer<String, AddTokenSuccess>(
(String selectedId, dynamic action) => action.token.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteTokensSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveTokensSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -19,7 +19,7 @@ Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, ViewUser>((String selectedId, action) => action.userId),
TypedReducer<String, AddUserSuccess>(
(String selectedId, action) => action.user.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteUserSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveUserSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -47,7 +47,7 @@ Reducer<String> selectedIdReducer = combineReducers([
TypedReducer<String, ViewVendor>((selectedId, action) => action.vendorId),
TypedReducer<String, AddVendorSuccess>(
(selectedId, action) => action.vendor.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteVendorSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveVendorSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -21,7 +21,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(String selectedId, dynamic action) => action.webhookId),
TypedReducer<String, AddWebhookSuccess>(
(String selectedId, dynamic action) => action.webhook.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteWebhooksSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveWebhooksSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),

View File

@ -60,7 +60,7 @@ class MenuDrawerVM {
onCompanyChanged:
(BuildContext context, String companyIndex, CompanyEntity company) {
store.dispatch(ClearEntityFilter());
store.dispatch(SelectCompany(int.parse(companyIndex)));
store.dispatch(SelectCompany(companyIndex: int.parse(companyIndex)));
if (store.state.isStale) {
if (!store.state.isLoaded && store.state.company.isLarge) {
store.dispatch(LoadClients());

View File

@ -66,7 +66,7 @@ class AccountManagementVM {
break;
}
}
store.dispatch(SelectCompany(index));
store.dispatch(SelectCompany(companyIndex: index));
store.dispatch(ViewDashboard(navigator: Navigator.of(context)));
} else {
store.dispatch(UserLogout(context));

View File

@ -21,7 +21,7 @@ Reducer<String> selectedIdReducer = combineReducers([
(String selectedId, dynamic action) => action.stubId),
TypedReducer<String, AddStubSuccess>(
(String selectedId, dynamic action) => action.stub.id),
TypedReducer<String, SelectCompany>((selectedId, action) => ''),
TypedReducer<String, SelectCompany>((selectedId, action) => action.clearSelection ? '' : selectedId),
TypedReducer<String, DeleteStubsSuccess>((selectedId, action) => ''),
TypedReducer<String, ArchiveStubsSuccess>((selectedId, action) => ''),
TypedReducer<String, ClearEntityFilter>((selectedId, action) => ''),