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 bool force;
LoadProducts([this.completer, this.force = false]);
LoadProducts({this.completer, this.force = false});
}
class LoadProductsRequest implements StartLoading {}

View File

@ -1,4 +1,3 @@
import 'dart:async';
import 'package:built_collection/built_collection.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:invoiceninja_flutter/ui/app/dialogs/error_dialog.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:redux/redux.dart';
import 'package:invoiceninja_flutter/data/models/models.dart';
@ -54,19 +54,16 @@ class ClientListVM {
});
static ClientListVM fromStore(Store<AppState> store) {
Future<Null> _handleRefresh(BuildContext context) {
final Completer<Null> completer = Completer<Null>();
store.dispatch(LoadClients(completer: completer, force: true));
return completer.future.then((_) {
Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow(
message: AppLocalization.of(context).refreshComplete,
)));
});
}
Future<Null> _handleRefresh(BuildContext context) {
final completer = snackBarCompleter(
context, AppLocalization.of(context).refreshComplete);
store.dispatch(LoadClients(completer: completer, force: true));
return completer.future;
}
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,
isLoading: store.state.isLoading,
isLoaded: store.state.clientState.isLoaded,
@ -98,7 +95,7 @@ class ClientListVM {
}
return completer.future.then((_) {
Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow(
content: SnackBarRow(
message: message,
)));
}).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/ui/app/dialogs/error_dialog.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:redux/redux.dart';
import 'package:invoiceninja_flutter/redux/invoice/invoice_actions.dart';
@ -66,14 +67,10 @@ class InvoiceViewVM {
final client = store.state.clientState.map[invoice.clientId];
Future<Null> _handleRefresh(BuildContext context) {
final Completer<InvoiceEntity> completer = Completer<InvoiceEntity>();
store.dispatch(LoadInvoice(completer: completer, invoiceId: invoice.id));
return completer.future.then((_) {
Scaffold.of(context).showSnackBar(SnackBar(
content: SnackBarRow(
message: AppLocalization.of(context).refreshComplete,
)));
});
final completer = snackBarCompleter(
context, AppLocalization.of(context).refreshComplete);
store.dispatch(LoadInvoices(completer: completer, force: true));
return completer.future;
}
Future<Null> _viewPdf(BuildContext context) async {

View File

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

View File

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