Refactor
This commit is contained in:
parent
bc55ae4ba1
commit
420f38c16b
|
|
@ -0,0 +1,2 @@
|
|||
class PersistData {}
|
||||
class PersistUI {}
|
||||
|
|
@ -1,12 +1,9 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:invoiceninja/data/file_storage.dart';
|
||||
import 'package:invoiceninja/data/repositories/persistence_repository.dart';
|
||||
import 'package:invoiceninja/redux/app/app_actions.dart';
|
||||
import 'package:invoiceninja/redux/app/app_state.dart';
|
||||
import 'package:invoiceninja/redux/auth/auth_actions.dart';
|
||||
import 'package:invoiceninja/redux/client/client_actions.dart';
|
||||
import 'package:invoiceninja/redux/dashboard/dashboard_actions.dart';
|
||||
import 'package:invoiceninja/redux/invoice/invoice_actions.dart';
|
||||
import 'package:invoiceninja/redux/product/product_actions.dart';
|
||||
import 'package:invoiceninja/ui/auth/login_vm.dart';
|
||||
import 'package:redux/redux.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
|
@ -91,26 +88,7 @@ List<Middleware<AppState>> createStorePersistenceMiddleware([
|
|||
TypedMiddleware<AppState, UserLogout>(deleteState),
|
||||
TypedMiddleware<AppState, LoadStateRequest>(loadState),
|
||||
TypedMiddleware<AppState, UserLoginSuccess>(userLoggedIn),
|
||||
|
||||
TypedMiddleware<AppState, LoadDashboardSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, LoadProductsSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, AddProductSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, SaveProductSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, ArchiveProductSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, DeleteProductSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, RestoreProductSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, LoadClientsSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, AddClientSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, SaveClientSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, ArchiveClientSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, DeleteClientSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, RestoreClientSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, LoadInvoicesSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, AddInvoiceSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, SaveInvoiceSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, ArchiveInvoiceSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, DeleteInvoiceSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, RestoreInvoiceSuccess>(dataLoaded),
|
||||
TypedMiddleware<AppState, PersistData>(dataLoaded),
|
||||
];
|
||||
}
|
||||
|
||||
|
|
@ -223,6 +201,8 @@ Middleware<AppState> _createDataLoaded(
|
|||
PersistenceRepository company5Repository,
|
||||
) {
|
||||
return (Store<AppState> store, action, NextDispatcher next) {
|
||||
print('== Data loaded');
|
||||
|
||||
// first process the action so the data is in the state
|
||||
next(action);
|
||||
|
||||
|
|
@ -233,16 +213,16 @@ Middleware<AppState> _createDataLoaded(
|
|||
company1Repository.saveCompanyState(state.companyState1);
|
||||
break;
|
||||
case 2:
|
||||
company1Repository.saveCompanyState(state.companyState2);
|
||||
company2Repository.saveCompanyState(state.companyState2);
|
||||
break;
|
||||
case 3:
|
||||
company1Repository.saveCompanyState(state.companyState3);
|
||||
company3Repository.saveCompanyState(state.companyState3);
|
||||
break;
|
||||
case 4:
|
||||
company1Repository.saveCompanyState(state.companyState4);
|
||||
company4Repository.saveCompanyState(state.companyState4);
|
||||
break;
|
||||
case 5:
|
||||
company1Repository.saveCompanyState(state.companyState5);
|
||||
company5Repository.saveCompanyState(state.companyState5);
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:invoiceninja/data/models/models.dart';
|
||||
import 'package:built_collection/built_collection.dart';
|
||||
import 'package:invoiceninja/redux/app/app_actions.dart';
|
||||
|
||||
class LoadClientsAction {
|
||||
final Completer completer;
|
||||
|
|
@ -22,7 +23,7 @@ class LoadClientsFailure {
|
|||
}
|
||||
}
|
||||
|
||||
class LoadClientsSuccess {
|
||||
class LoadClientsSuccess extends PersistData {
|
||||
final BuiltList<ClientEntity> clients;
|
||||
LoadClientsSuccess(this.clients);
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ class SaveClientRequest {
|
|||
SaveClientRequest(this.completer, this.client);
|
||||
}
|
||||
|
||||
class SaveClientSuccess {
|
||||
class SaveClientSuccess extends PersistData {
|
||||
final ClientEntity client;
|
||||
|
||||
SaveClientSuccess(this.client);
|
||||
|
|
@ -55,7 +56,7 @@ class ArchiveClientRequest {
|
|||
|
||||
ArchiveClientRequest(this.completer, this.clientId);
|
||||
}
|
||||
class ArchiveClientSuccess {
|
||||
class ArchiveClientSuccess extends PersistData {
|
||||
final ClientEntity client;
|
||||
ArchiveClientSuccess(this.client);
|
||||
}
|
||||
|
|
@ -70,7 +71,7 @@ class DeleteClientRequest {
|
|||
|
||||
DeleteClientRequest(this.completer, this.clientId);
|
||||
}
|
||||
class DeleteClientSuccess {
|
||||
class DeleteClientSuccess extends PersistData {
|
||||
final ClientEntity client;
|
||||
DeleteClientSuccess(this.client);
|
||||
}
|
||||
|
|
@ -84,7 +85,7 @@ class RestoreClientRequest {
|
|||
final int clientId;
|
||||
RestoreClientRequest(this.completer, this.clientId);
|
||||
}
|
||||
class RestoreClientSuccess {
|
||||
class RestoreClientSuccess extends PersistData {
|
||||
final ClientEntity client;
|
||||
RestoreClientSuccess(this.client);
|
||||
}
|
||||
|
|
@ -93,7 +94,7 @@ class RestoreClientFailure {
|
|||
RestoreClientFailure(this.client);
|
||||
}
|
||||
|
||||
class AddClientSuccess {
|
||||
class AddClientSuccess extends PersistData {
|
||||
final ClientEntity client;
|
||||
AddClientSuccess(this.client);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:invoiceninja/data/models/models.dart';
|
||||
import 'package:invoiceninja/redux/app/app_actions.dart';
|
||||
|
||||
class LoadDashboardAction {
|
||||
final Completer completer;
|
||||
|
|
@ -22,7 +23,7 @@ class LoadDashboardFailure {
|
|||
}
|
||||
}
|
||||
|
||||
class LoadDashboardSuccess {
|
||||
class LoadDashboardSuccess extends PersistData {
|
||||
final DashboardEntity data;
|
||||
|
||||
LoadDashboardSuccess(this.data);
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
|
||||
import 'package:invoiceninja/data/models/models.dart';
|
||||
import 'package:built_collection/built_collection.dart';
|
||||
import 'package:invoiceninja/redux/app/app_actions.dart';
|
||||
|
||||
class LoadInvoicesAction {
|
||||
final Completer completer;
|
||||
|
|
@ -22,7 +23,7 @@ class LoadInvoicesFailure {
|
|||
}
|
||||
}
|
||||
|
||||
class LoadInvoicesSuccess {
|
||||
class LoadInvoicesSuccess extends PersistData {
|
||||
final BuiltList<InvoiceEntity> invoices;
|
||||
LoadInvoicesSuccess(this.invoices);
|
||||
|
||||
|
|
@ -43,7 +44,7 @@ class SaveInvoiceRequest {
|
|||
SaveInvoiceRequest(this.completer, this.invoice);
|
||||
}
|
||||
|
||||
class SaveInvoiceSuccess {
|
||||
class SaveInvoiceSuccess extends PersistData {
|
||||
final InvoiceEntity invoice;
|
||||
|
||||
SaveInvoiceSuccess(this.invoice);
|
||||
|
|
@ -55,7 +56,7 @@ class ArchiveInvoiceRequest {
|
|||
|
||||
ArchiveInvoiceRequest(this.completer, this.invoiceId);
|
||||
}
|
||||
class ArchiveInvoiceSuccess {
|
||||
class ArchiveInvoiceSuccess extends PersistData {
|
||||
final InvoiceEntity invoice;
|
||||
ArchiveInvoiceSuccess(this.invoice);
|
||||
}
|
||||
|
|
@ -70,7 +71,7 @@ class DeleteInvoiceRequest {
|
|||
|
||||
DeleteInvoiceRequest(this.completer, this.invoiceId);
|
||||
}
|
||||
class DeleteInvoiceSuccess {
|
||||
class DeleteInvoiceSuccess extends PersistData {
|
||||
final InvoiceEntity invoice;
|
||||
DeleteInvoiceSuccess(this.invoice);
|
||||
}
|
||||
|
|
@ -84,7 +85,7 @@ class RestoreInvoiceRequest {
|
|||
final int invoiceId;
|
||||
RestoreInvoiceRequest(this.completer, this.invoiceId);
|
||||
}
|
||||
class RestoreInvoiceSuccess {
|
||||
class RestoreInvoiceSuccess extends PersistData {
|
||||
final InvoiceEntity invoice;
|
||||
RestoreInvoiceSuccess(this.invoice);
|
||||
}
|
||||
|
|
@ -93,7 +94,7 @@ class RestoreInvoiceFailure {
|
|||
RestoreInvoiceFailure(this.invoice);
|
||||
}
|
||||
|
||||
class AddInvoiceSuccess {
|
||||
class AddInvoiceSuccess extends PersistData {
|
||||
final InvoiceEntity invoice;
|
||||
AddInvoiceSuccess(this.invoice);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:invoiceninja/data/models/models.dart';
|
||||
import 'package:built_collection/built_collection.dart';
|
||||
import 'package:invoiceninja/redux/app/app_actions.dart';
|
||||
|
||||
class LoadProductsAction {
|
||||
final Completer completer;
|
||||
|
|
@ -22,7 +23,7 @@ class LoadProductsFailure {
|
|||
}
|
||||
}
|
||||
|
||||
class LoadProductsSuccess {
|
||||
class LoadProductsSuccess extends PersistData {
|
||||
final BuiltList<ProductEntity> products;
|
||||
LoadProductsSuccess(this.products);
|
||||
|
||||
|
|
@ -44,7 +45,7 @@ class SaveProductRequest {
|
|||
SaveProductRequest(this.completer, this.product);
|
||||
}
|
||||
|
||||
class SaveProductSuccess {
|
||||
class SaveProductSuccess extends PersistData {
|
||||
final ProductEntity product;
|
||||
|
||||
SaveProductSuccess(this.product);
|
||||
|
|
@ -56,7 +57,7 @@ class ArchiveProductRequest {
|
|||
|
||||
ArchiveProductRequest(this.completer, this.productId);
|
||||
}
|
||||
class ArchiveProductSuccess {
|
||||
class ArchiveProductSuccess extends PersistData {
|
||||
final ProductEntity product;
|
||||
ArchiveProductSuccess(this.product);
|
||||
}
|
||||
|
|
@ -71,7 +72,7 @@ class DeleteProductRequest {
|
|||
|
||||
DeleteProductRequest(this.completer, this.productId);
|
||||
}
|
||||
class DeleteProductSuccess {
|
||||
class DeleteProductSuccess extends PersistData {
|
||||
final ProductEntity product;
|
||||
DeleteProductSuccess(this.product);
|
||||
}
|
||||
|
|
@ -85,7 +86,7 @@ class RestoreProductRequest {
|
|||
final int productId;
|
||||
RestoreProductRequest(this.completer, this.productId);
|
||||
}
|
||||
class RestoreProductSuccess {
|
||||
class RestoreProductSuccess extends PersistData {
|
||||
final ProductEntity product;
|
||||
RestoreProductSuccess(this.product);
|
||||
}
|
||||
|
|
@ -94,7 +95,7 @@ class RestoreProductFailure {
|
|||
RestoreProductFailure(this.product);
|
||||
}
|
||||
|
||||
class AddProductSuccess {
|
||||
class AddProductSuccess extends PersistData {
|
||||
final ProductEntity product;
|
||||
AddProductSuccess(this.product);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue