Fix loading data

This commit is contained in:
Hillel Coren 2019-09-23 21:20:10 +03:00
parent afde837684
commit 280e0f7e9e
11 changed files with 46 additions and 6 deletions

View File

@ -301,31 +301,41 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
InvoiceEmailScreen.route: (context) => InvoiceEmailScreen(), InvoiceEmailScreen.route: (context) => InvoiceEmailScreen(),
// STARTER: routes - do not remove comment // STARTER: routes - do not remove comment
DocumentScreen.route: (context) { DocumentScreen.route: (context) {
widget.store.dispatch(LoadDocuments()); if (widget.store.state.documentState.isStale) {
widget.store.dispatch(LoadDocuments());
}
return DocumentScreen(); return DocumentScreen();
}, },
DocumentViewScreen.route: (context) => DocumentViewScreen(), DocumentViewScreen.route: (context) => DocumentViewScreen(),
DocumentEditScreen.route: (context) => DocumentEditScreen(), DocumentEditScreen.route: (context) => DocumentEditScreen(),
ExpenseScreen.route: (context) { ExpenseScreen.route: (context) {
widget.store.dispatch(LoadExpenses()); if (widget.store.state.expenseState.isStale) {
widget.store.dispatch(LoadExpenses());
}
return ExpenseScreen(); return ExpenseScreen();
}, },
ExpenseViewScreen.route: (context) => ExpenseViewScreen(), ExpenseViewScreen.route: (context) => ExpenseViewScreen(),
ExpenseEditScreen.route: (context) => ExpenseEditScreen(), ExpenseEditScreen.route: (context) => ExpenseEditScreen(),
VendorScreen.route: (context) { VendorScreen.route: (context) {
widget.store.dispatch(LoadVendors()); if (widget.store.state.vendorState.isStale) {
widget.store.dispatch(LoadVendors());
}
return VendorScreen(); return VendorScreen();
}, },
VendorViewScreen.route: (context) => VendorViewScreen(), VendorViewScreen.route: (context) => VendorViewScreen(),
VendorEditScreen.route: (context) => VendorEditScreen(), VendorEditScreen.route: (context) => VendorEditScreen(),
TaskScreen.route: (context) { TaskScreen.route: (context) {
widget.store.dispatch(LoadTasks()); if (widget.store.state.taskState.isStale) {
widget.store.dispatch(LoadTasks());
}
return TaskScreen(); return TaskScreen();
}, },
TaskViewScreen.route: (context) => TaskViewScreen(), TaskViewScreen.route: (context) => TaskViewScreen(),
TaskEditScreen.route: (context) => TaskEditScreen(), TaskEditScreen.route: (context) => TaskEditScreen(),
ProjectScreen.route: (context) { ProjectScreen.route: (context) {
widget.store.dispatch(LoadProjects()); if (widget.store.state.projectState.isStale) {
widget.store.dispatch(LoadProjects());
}
return ProjectScreen(); return ProjectScreen();
}, },
ProjectViewScreen.route: (context) => ProjectViewScreen(), ProjectViewScreen.route: (context) => ProjectViewScreen(),

View File

@ -94,6 +94,8 @@ Middleware<AppState> _viewClientList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
ClientScreen.route, (Route<dynamic> route) => false); ClientScreen.route, (Route<dynamic> route) => false);
} else if (store.state.clientState.isStale) {
store.dispatch(LoadClients());
} }
}; };
} }

View File

@ -101,6 +101,8 @@ Middleware<AppState> _viewExpenseList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
ExpenseScreen.route, (Route<dynamic> route) => false); ExpenseScreen.route, (Route<dynamic> route) => false);
} else if (store.state.expenseState.isStale) {
store.dispatch(LoadExpenses());
} }
}; };
} }

View File

@ -65,6 +65,8 @@ Middleware<AppState> _viewInvoiceList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
InvoiceScreen.route, (Route<dynamic> route) => false); InvoiceScreen.route, (Route<dynamic> route) => false);
} else if (store.state.invoiceState.isStale) {
store.dispatch(LoadInvoices());
} }
}; };
} }

View File

@ -100,6 +100,8 @@ Middleware<AppState> _viewPaymentList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
PaymentScreen.route, (Route<dynamic> route) => false); PaymentScreen.route, (Route<dynamic> route) => false);
} else if (store.state.paymentState.isStale) {
store.dispatch(LoadPayments());
} }
}; };
} }

View File

@ -92,6 +92,8 @@ Middleware<AppState> _viewProductList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
ProductScreen.route, (Route<dynamic> route) => false); ProductScreen.route, (Route<dynamic> route) => false);
} else if (store.state.productState.isStale) {
store.dispatch(LoadProducts());
} }
}; };
} }

View File

@ -101,6 +101,8 @@ Middleware<AppState> _viewProjectList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
ProjectScreen.route, (Route<dynamic> route) => false); ProjectScreen.route, (Route<dynamic> route) => false);
} else if (store.state.projectState.isStale) {
store.dispatch(LoadProjects());
} }
}; };
} }

View File

@ -78,6 +78,8 @@ Middleware<AppState> _viewQuoteList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
QuoteScreen.route, (Route<dynamic> route) => false); QuoteScreen.route, (Route<dynamic> route) => false);
} else if (store.state.quoteState.isStale) {
store.dispatch(LoadQuotes());
} }
}; };
} }

View File

@ -100,6 +100,8 @@ Middleware<AppState> _viewTaskList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
TaskScreen.route, (Route<dynamic> route) => false); TaskScreen.route, (Route<dynamic> route) => false);
} else if (store.state.taskState.isStale) {
store.dispatch(LoadTasks());
} }
}; };
} }

View File

@ -101,6 +101,8 @@ Middleware<AppState> _viewVendorList() {
if (isMobile(action.context)) { if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil( Navigator.of(action.context).pushNamedAndRemoveUntil(
VendorScreen.route, (Route<dynamic> route) => false); VendorScreen.route, (Route<dynamic> route) => false);
} else if (store.state.vendorState.isStale) {
store.dispatch(LoadVendors());
} }
}; };
} }

View File

@ -72,11 +72,23 @@ Middleware<AppState> _viewStub() {
Middleware<AppState> _viewStubList() { Middleware<AppState> _viewStubList() {
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) { return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
final action = dynamicAction as ViewStubList;
if (hasChanges(
store: store, context: action.context, force: action.force)) {
return;
}
next(action); next(action);
store.dispatch(UpdateCurrentRoute(StubScreen.route)); store.dispatch(UpdateCurrentRoute(StubScreen.route));
Navigator.of(action.context).pushNamedAndRemoveUntil(StubScreen.route, (Route<dynamic> route) => false); if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
StubScreen.route, (Route<dynamic> route) => false);
} else if (store.state.stubState.isStale) {
store.dispatch(LoadStubs());
}
}; };
} }