Clean up startup

This commit is contained in:
unknown 2018-06-19 04:59:40 -07:00
parent fbfecb6a8b
commit f125db74ce
7 changed files with 38 additions and 17 deletions

View File

@ -1,5 +1,6 @@
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:invoiceninja/data/file_storage.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/data/repositories/persistence_repository.dart';
import 'package:invoiceninja/redux/app/app_actions.dart'; import 'package:invoiceninja/redux/app/app_actions.dart';
import 'package:invoiceninja/redux/app/app_state.dart'; import 'package:invoiceninja/redux/app/app_state.dart';
@ -172,21 +173,29 @@ Middleware<AppState> _createLoadState(
List<String> _getRoutes(AppState state) { List<String> _getRoutes(AppState state) {
List<String> routes = []; List<String> routes = [];
var route = ''; var route = '';
EntityType entityType = null;
state.uiState.currentRoute.split('/').forEach((part) { state.uiState.currentRoute
if (part.isNotEmpty) { .split('/')
// TODO automatically lookup state using the route/entity type .where((part) => part.isNotEmpty)
if (part == 'edit' && route != '/product' && route != '/invoice') { .forEach((part) {
switch (route) { if (part == 'edit') {
case '/client': // Only restore new unsaved entities to prevent conflicts
if (! state.clientUIState.selected.isNew()) { bool isNew = state.getUIState(entityType).isSelectedNew;
routes.add(route + '/view'); if (isNew) {
} route += '/edit';
} else if (entityType == EntityType.client) {
route += '/view';
} }
} else {
if (entityType == null) {
entityType = EntityType.valueOf(part);
} }
route += '/' + part; route += '/' + part;
routes.add(route);
} }
routes.add(route);
}); });
return routes; return routes;

View File

@ -1,6 +1,7 @@
import 'package:invoiceninja/data/models/models.dart'; import 'package:invoiceninja/data/models/models.dart';
import 'package:invoiceninja/redux/client/client_state.dart'; import 'package:invoiceninja/redux/client/client_state.dart';
import 'package:invoiceninja/redux/invoice/invoice_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/ui_state.dart';
import 'package:invoiceninja/redux/ui/list_ui_state.dart'; import 'package:invoiceninja/redux/ui/list_ui_state.dart';
import 'package:invoiceninja/redux/auth/auth_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; CompanyEntity get selectedCompany => this.selectedCompanyState.company;
DashboardState get dashboardState => this.selectedCompanyState.dashboardState; DashboardState get dashboardState => this.selectedCompanyState.dashboardState;
ListUIState getListState(EntityType type) { EntityUIState getUIState(EntityType type) {
switch (type) { switch (type) {
case EntityType.product: case EntityType.product:
return productListState; return productUIState;
case EntityType.client: case EntityType.client:
return clientListState; return clientUIState;
case EntityType.invoice: case EntityType.invoice:
return invoiceListState; return invoiceUIState;
default: default:
return null; return null;
} }
} }
ListUIState getListState(EntityType type) {
return getUIState(type).listUIState;
}
ProductState get productState => this.selectedCompanyState.productState; ProductState get productState => this.selectedCompanyState.productState;
ProductUIState get productUIState => this.uiState.productUIState; ProductUIState get productUIState => this.uiState.productUIState;
ListUIState get productListState => this.uiState.productUIState.listUIState; ListUIState get productListState => this.uiState.productUIState.listUIState;

View File

@ -44,6 +44,8 @@ abstract class ClientUIState extends Object with EntityUIState implements Built<
@nullable @nullable
ClientEntity get selected; ClientEntity get selected;
bool get isSelectedNew => selected.isNew();
factory ClientUIState() { factory ClientUIState() {
return _$ClientUIState._( return _$ClientUIState._(
listUIState: ListUIState(ClientFields.name), listUIState: ListUIState(ClientFields.name),

View File

@ -44,6 +44,8 @@ abstract class InvoiceUIState extends Object with EntityUIState implements Built
@nullable @nullable
InvoiceEntity get selected; InvoiceEntity get selected;
bool get isSelectedNew => selected.isNew();
factory InvoiceUIState() { factory InvoiceUIState() {
return _$InvoiceUIState._( return _$InvoiceUIState._(
listUIState: ListUIState(InvoiceFields.invoiceNumber), listUIState: ListUIState(InvoiceFields.invoiceNumber),

View File

@ -44,6 +44,8 @@ abstract class ProductUIState extends Object with EntityUIState implements Built
@nullable @nullable
ProductEntity get selected; ProductEntity get selected;
bool get isSelectedNew => selected.isNew();
factory ProductUIState() { factory ProductUIState() {
return _$ProductUIState._( return _$ProductUIState._(
listUIState: ListUIState(ProductFields.productKey), listUIState: ListUIState(ProductFields.productKey),

View File

@ -2,6 +2,7 @@ import 'package:invoiceninja/redux/ui/list_ui_state.dart';
abstract class EntityUIState { abstract class EntityUIState {
bool get isSelectedNew;
ListUIState get listUIState; ListUIState get listUIState;
} }

View File

@ -59,7 +59,7 @@ class _InvoiceEditState extends State<InvoiceEdit>
appBar: AppBar( appBar: AppBar(
title: Text(invoice.isNew() title: Text(invoice.isNew()
? localization.newInvoice ? localization.newInvoice
: invoice.invoiceNumber), : '${localization.invoice} ${invoice.invoiceNumber}'),
actions: <Widget>[ actions: <Widget>[
SaveIconButton( SaveIconButton(
isLoading: widget.viewModel.isLoading, isLoading: widget.viewModel.isLoading,