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(),
// STARTER: routes - do not remove comment
DocumentScreen.route: (context) {
widget.store.dispatch(LoadDocuments());
if (widget.store.state.documentState.isStale) {
widget.store.dispatch(LoadDocuments());
}
return DocumentScreen();
},
DocumentViewScreen.route: (context) => DocumentViewScreen(),
DocumentEditScreen.route: (context) => DocumentEditScreen(),
ExpenseScreen.route: (context) {
widget.store.dispatch(LoadExpenses());
if (widget.store.state.expenseState.isStale) {
widget.store.dispatch(LoadExpenses());
}
return ExpenseScreen();
},
ExpenseViewScreen.route: (context) => ExpenseViewScreen(),
ExpenseEditScreen.route: (context) => ExpenseEditScreen(),
VendorScreen.route: (context) {
widget.store.dispatch(LoadVendors());
if (widget.store.state.vendorState.isStale) {
widget.store.dispatch(LoadVendors());
}
return VendorScreen();
},
VendorViewScreen.route: (context) => VendorViewScreen(),
VendorEditScreen.route: (context) => VendorEditScreen(),
TaskScreen.route: (context) {
widget.store.dispatch(LoadTasks());
if (widget.store.state.taskState.isStale) {
widget.store.dispatch(LoadTasks());
}
return TaskScreen();
},
TaskViewScreen.route: (context) => TaskViewScreen(),
TaskEditScreen.route: (context) => TaskEditScreen(),
ProjectScreen.route: (context) {
widget.store.dispatch(LoadProjects());
if (widget.store.state.projectState.isStale) {
widget.store.dispatch(LoadProjects());
}
return ProjectScreen();
},
ProjectViewScreen.route: (context) => ProjectViewScreen(),

View File

@ -94,6 +94,8 @@ Middleware<AppState> _viewClientList() {
if (isMobile(action.context)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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)) {
Navigator.of(action.context).pushNamedAndRemoveUntil(
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() {
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);
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());
}
};
}