This commit is contained in:
unknown 2018-08-07 12:14:30 +03:00
parent 1ac6f98437
commit 15a0ab8994
5 changed files with 33 additions and 40 deletions

View File

@ -25,7 +25,7 @@ class LoadProducts {
final Completer completer; final Completer completer;
final bool force; final bool force;
LoadProducts([this.completer, this.force = false]); LoadProducts({this.completer, this.force = false});
} }
class LoadProductsRequest implements StartLoading {} class LoadProductsRequest implements StartLoading {}

View File

@ -1,4 +1,3 @@
import 'dart:async'; import 'dart:async';
import 'package:built_collection/built_collection.dart'; import 'package:built_collection/built_collection.dart';
import 'package:invoiceninja_flutter/redux/client/client_selectors.dart'; import 'package:invoiceninja_flutter/redux/client/client_selectors.dart';
@ -8,6 +7,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
import 'package:invoiceninja_flutter/ui/app/snackbar_row.dart'; import 'package:invoiceninja_flutter/ui/app/snackbar_row.dart';
import 'package:invoiceninja_flutter/utils/completers.dart';
import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:redux/redux.dart'; import 'package:redux/redux.dart';
import 'package:invoiceninja_flutter/data/models/models.dart'; import 'package:invoiceninja_flutter/data/models/models.dart';
@ -54,19 +54,16 @@ class ClientListVM {
}); });
static ClientListVM fromStore(Store<AppState> store) { static ClientListVM fromStore(Store<AppState> store) {
Future<Null> _handleRefresh(BuildContext context) { Future<Null> _handleRefresh(BuildContext context) {
final Completer<Null> completer = Completer<Null>(); final completer = snackBarCompleter(
store.dispatch(LoadClients(completer: completer, force: true)); context, AppLocalization.of(context).refreshComplete);
return completer.future.then((_) { store.dispatch(LoadClients(completer: completer, force: true));
Scaffold.of(context).showSnackBar(SnackBar( return completer.future;
content: SnackBarRow( }
message: AppLocalization.of(context).refreshComplete,
)));
});
}
return ClientListVM( return ClientListVM(
clientList: memoizedFilteredClientList(store.state.clientState.map, store.state.clientState.list, store.state.clientListState), clientList: memoizedFilteredClientList(store.state.clientState.map,
store.state.clientState.list, store.state.clientListState),
clientMap: store.state.clientState.map, clientMap: store.state.clientState.map,
isLoading: store.state.isLoading, isLoading: store.state.isLoading,
isLoaded: store.state.clientState.isLoaded, isLoaded: store.state.clientState.isLoaded,
@ -98,7 +95,7 @@ class ClientListVM {
} }
return completer.future.then((_) { return completer.future.then((_) {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow( content: SnackBarRow(
message: message, message: message,
))); )));
}).catchError((Object error) { }).catchError((Object error) {

View File

@ -6,6 +6,7 @@ import 'package:invoiceninja_flutter/redux/client/client_actions.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart'; import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
import 'package:invoiceninja_flutter/ui/invoice/invoice_screen.dart'; import 'package:invoiceninja_flutter/ui/invoice/invoice_screen.dart';
import 'package:invoiceninja_flutter/utils/completers.dart';
import 'package:invoiceninja_flutter/utils/localization.dart'; import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:redux/redux.dart'; import 'package:redux/redux.dart';
import 'package:invoiceninja_flutter/redux/invoice/invoice_actions.dart'; import 'package:invoiceninja_flutter/redux/invoice/invoice_actions.dart';
@ -66,14 +67,10 @@ class InvoiceViewVM {
final client = store.state.clientState.map[invoice.clientId]; final client = store.state.clientState.map[invoice.clientId];
Future<Null> _handleRefresh(BuildContext context) { Future<Null> _handleRefresh(BuildContext context) {
final Completer<InvoiceEntity> completer = Completer<InvoiceEntity>(); final completer = snackBarCompleter(
store.dispatch(LoadInvoice(completer: completer, invoiceId: invoice.id)); context, AppLocalization.of(context).refreshComplete);
return completer.future.then((_) { store.dispatch(LoadInvoices(completer: completer, force: true));
Scaffold.of(context).showSnackBar(SnackBar( return completer.future;
content: SnackBarRow(
message: AppLocalization.of(context).refreshComplete,
)));
});
} }
Future<Null> _viewPdf(BuildContext context) async { Future<Null> _viewPdf(BuildContext context) async {

View File

@ -55,23 +55,21 @@ class ProductListVM {
static ProductListVM fromStore(Store<AppState> store) { static ProductListVM fromStore(Store<AppState> store) {
Future<Null> _handleRefresh(BuildContext context) { Future<Null> _handleRefresh(BuildContext context) {
final Completer<Null> completer = Completer<Null>(); final completer = snackBarCompleter(
store.dispatch(LoadProducts(completer, true)); context, AppLocalization.of(context).refreshComplete);
return completer.future.then((_) { store.dispatch(LoadProducts(completer: completer, force: true));
Scaffold.of(context).showSnackBar(SnackBar( return completer.future;
content: SnackBarRow(
message: AppLocalization.of(context).refreshComplete,
)));
});
} }
final state = store.state;
return ProductListVM( return ProductListVM(
productList: memoizedFilteredProductList(store.state.productState.map, productList: memoizedFilteredProductList(state.productState.map,
store.state.productState.list, store.state.productListState), state.productState.list, state.productListState),
productMap: store.state.productState.map, productMap: state.productState.map,
isLoading: store.state.isLoading, isLoading: state.isLoading,
isLoaded: store.state.productState.isLoaded, isLoaded: state.productState.isLoaded,
filter: store.state.productUIState.listUIState.filter, filter: state.productUIState.listUIState.filter,
onProductTap: (context, product) { onProductTap: (context, product) {
store.dispatch(EditProduct(product: product, context: context)); store.dispatch(EditProduct(product: product, context: context));
}, },

View File

@ -2,9 +2,10 @@ import 'dart:async';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart'; import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
import 'package:invoiceninja_flutter/ui/app/snackbar_row.dart'; import 'package:invoiceninja_flutter/ui/app/snackbar_row.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
Completer<String> snackBarCompleter(BuildContext context, String message) { Completer<Null> snackBarCompleter(BuildContext context, String message) {
final Completer<String> completer = Completer<String>(); final Completer<Null> completer = Completer<Null>();
completer.future.then((_) { completer.future.then((_) {
Scaffold.of(context).showSnackBar(SnackBar( Scaffold.of(context).showSnackBar(SnackBar(
@ -22,8 +23,8 @@ Completer<String> snackBarCompleter(BuildContext context, String message) {
return completer; return completer;
} }
Completer<String> popCompleter(BuildContext context, String message) { Completer<Null> popCompleter(BuildContext context, String message) {
final Completer<String> completer = Completer<String>(); final Completer<Null> completer = Completer<Null>();
completer.future.then((_) { completer.future.then((_) {
Navigator.of(context).pop(message); Navigator.of(context).pop(message);