Clean up startup
This commit is contained in:
parent
fbfecb6a8b
commit
f125db74ce
|
|
@ -1,5 +1,6 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'package:invoiceninja/data/file_storage.dart';
|
||||
import 'package:invoiceninja/data/models/models.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';
|
||||
|
|
@ -172,21 +173,29 @@ Middleware<AppState> _createLoadState(
|
|||
List<String> _getRoutes(AppState state) {
|
||||
List<String> routes = [];
|
||||
var route = '';
|
||||
EntityType entityType = null;
|
||||
|
||||
state.uiState.currentRoute.split('/').forEach((part) {
|
||||
if (part.isNotEmpty) {
|
||||
// TODO automatically lookup state using the route/entity type
|
||||
if (part == 'edit' && route != '/product' && route != '/invoice') {
|
||||
switch (route) {
|
||||
case '/client':
|
||||
if (! state.clientUIState.selected.isNew()) {
|
||||
routes.add(route + '/view');
|
||||
}
|
||||
state.uiState.currentRoute
|
||||
.split('/')
|
||||
.where((part) => part.isNotEmpty)
|
||||
.forEach((part) {
|
||||
if (part == 'edit') {
|
||||
// Only restore new unsaved entities to prevent conflicts
|
||||
bool isNew = state.getUIState(entityType).isSelectedNew;
|
||||
if (isNew) {
|
||||
route += '/edit';
|
||||
} else if (entityType == EntityType.client) {
|
||||
route += '/view';
|
||||
}
|
||||
} else {
|
||||
if (entityType == null) {
|
||||
entityType = EntityType.valueOf(part);
|
||||
}
|
||||
|
||||
route += '/' + part;
|
||||
routes.add(route);
|
||||
}
|
||||
|
||||
routes.add(route);
|
||||
});
|
||||
|
||||
return routes;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import 'package:invoiceninja/data/models/models.dart';
|
||||
import 'package:invoiceninja/redux/client/client_state.dart';
|
||||
import 'package:invoiceninja/redux/invoice/invoice_state.dart';
|
||||
import 'package:invoiceninja/redux/ui/entity_ui_state.dart';
|
||||
import 'package:invoiceninja/redux/ui/ui_state.dart';
|
||||
import 'package:invoiceninja/redux/ui/list_ui_state.dart';
|
||||
import 'package:invoiceninja/redux/auth/auth_state.dart';
|
||||
|
|
@ -65,19 +66,23 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
|
|||
CompanyEntity get selectedCompany => this.selectedCompanyState.company;
|
||||
DashboardState get dashboardState => this.selectedCompanyState.dashboardState;
|
||||
|
||||
ListUIState getListState(EntityType type) {
|
||||
EntityUIState getUIState(EntityType type) {
|
||||
switch (type) {
|
||||
case EntityType.product:
|
||||
return productListState;
|
||||
return productUIState;
|
||||
case EntityType.client:
|
||||
return clientListState;
|
||||
return clientUIState;
|
||||
case EntityType.invoice:
|
||||
return invoiceListState;
|
||||
return invoiceUIState;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
ListUIState getListState(EntityType type) {
|
||||
return getUIState(type).listUIState;
|
||||
}
|
||||
|
||||
ProductState get productState => this.selectedCompanyState.productState;
|
||||
ProductUIState get productUIState => this.uiState.productUIState;
|
||||
ListUIState get productListState => this.uiState.productUIState.listUIState;
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ abstract class ClientUIState extends Object with EntityUIState implements Built<
|
|||
@nullable
|
||||
ClientEntity get selected;
|
||||
|
||||
bool get isSelectedNew => selected.isNew();
|
||||
|
||||
factory ClientUIState() {
|
||||
return _$ClientUIState._(
|
||||
listUIState: ListUIState(ClientFields.name),
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ abstract class InvoiceUIState extends Object with EntityUIState implements Built
|
|||
@nullable
|
||||
InvoiceEntity get selected;
|
||||
|
||||
bool get isSelectedNew => selected.isNew();
|
||||
|
||||
factory InvoiceUIState() {
|
||||
return _$InvoiceUIState._(
|
||||
listUIState: ListUIState(InvoiceFields.invoiceNumber),
|
||||
|
|
|
|||
|
|
@ -44,6 +44,8 @@ abstract class ProductUIState extends Object with EntityUIState implements Built
|
|||
@nullable
|
||||
ProductEntity get selected;
|
||||
|
||||
bool get isSelectedNew => selected.isNew();
|
||||
|
||||
factory ProductUIState() {
|
||||
return _$ProductUIState._(
|
||||
listUIState: ListUIState(ProductFields.productKey),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import 'package:invoiceninja/redux/ui/list_ui_state.dart';
|
|||
|
||||
abstract class EntityUIState {
|
||||
|
||||
bool get isSelectedNew;
|
||||
ListUIState get listUIState;
|
||||
|
||||
}
|
||||
|
|
@ -59,7 +59,7 @@ class _InvoiceEditState extends State<InvoiceEdit>
|
|||
appBar: AppBar(
|
||||
title: Text(invoice.isNew()
|
||||
? localization.newInvoice
|
||||
: invoice.invoiceNumber),
|
||||
: '${localization.invoice} ${invoice.invoiceNumber}'),
|
||||
actions: <Widget>[
|
||||
SaveIconButton(
|
||||
isLoading: widget.viewModel.isLoading,
|
||||
|
|
|
|||
Loading…
Reference in New Issue