This commit is contained in:
Hillel Coren 2018-12-18 17:08:57 +02:00
parent 3c866714d6
commit 7e0eb3626f
15 changed files with 62 additions and 23 deletions

View File

@ -74,4 +74,6 @@ ProjectUIState get projectUIState;
QuoteUIState get quoteUIState;
static Serializer<UIState> get serializer => _$uIStateSerializer;
bool containsRoute(String route) => currentRoute.contains(route);
}

View File

@ -60,8 +60,11 @@ class ClientEditVM {
origClient: state.clientState.map[client.id],
staticState: state.staticState,
isSaving: state.isSaving,
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(ClientScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(ClientScreen.route)) {
store.dispatch(UpdateCurrentRoute(ClientViewScreen.route));
}
},
onChanged: (ClientEntity client) =>
store.dispatch(UpdateClient(client)),
onSavePressed: (BuildContext context) {

View File

@ -109,8 +109,11 @@ class ClientViewVM {
},
onRefreshed: (context, loadActivities) =>
_handleRefresh(context, loadActivities),
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(ClientScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(ClientScreen.route)) {
store.dispatch(UpdateCurrentRoute(ClientScreen.route));
}
},
onActionSelected: (BuildContext context, EntityAction action) {
final localization = AppLocalization.of(context);
switch (action) {

View File

@ -85,8 +85,11 @@ class InvoiceEditVM extends EntityEditVM {
invoice: invoice,
invoiceItem: state.invoiceUIState.editingItem,
origInvoice: store.state.invoiceState.map[invoice.id],
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(InvoiceScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(InvoiceScreen.route)) {
store.dispatch(UpdateCurrentRoute(InvoiceViewScreen.route));
}
},
onSavePressed: (BuildContext context) {
final Completer<InvoiceEntity> completer = Completer<InvoiceEntity>();
store.dispatch(

View File

@ -149,8 +149,11 @@ class InvoiceViewVM extends EntityViewVM {
});
},
onRefreshed: (context) => _handleRefresh(context),
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(InvoiceScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(InvoiceScreen.route)) {
store.dispatch(UpdateCurrentRoute(InvoiceScreen.route));
}
},
onClientPressed: (BuildContext context) =>
store.dispatch(ViewClient(clientId: client.id, context: context)),
onPaymentPressed: (BuildContext context, PaymentEntity payment) => store

View File

@ -83,7 +83,9 @@ class PaymentEditVM {
store.dispatch(UserSettingsChanged(emailPayment: value));
},
onBackPressed: () {
store.dispatch(UpdateCurrentRoute(PaymentScreen.route));
if (state.uiState.currentRoute.contains(PaymentScreen.route)) {
store.dispatch(UpdateCurrentRoute(PaymentViewScreen.route));
}
},
onSavePressed: (BuildContext context) {
final Completer<Null> completer = errorCompleter(context)

View File

@ -58,7 +58,9 @@ class ProductEditVM {
store.dispatch(UpdateProduct(product));
},
onBackPressed: () {
store.dispatch(UpdateCurrentRoute(ProductScreen.route));
if (state.uiState.currentRoute.contains(ProductScreen.route)) {
store.dispatch(UpdateCurrentRoute(ProductScreen.route));
}
},
onSavePressed: (BuildContext context) {
store.dispatch(SaveProductRequest(

View File

@ -68,7 +68,9 @@ class ProjectEditVM {
store.dispatch(UpdateProject(project));
},
onBackPressed: () {
store.dispatch(UpdateCurrentRoute(ProjectScreen.route));
if (state.uiState.currentRoute.contains(ProjectScreen.route)) {
store.dispatch(UpdateCurrentRoute(ProjectViewScreen.route));
}
},
onAddClientPressed: (context, completer) {
store.dispatch(EditClient(

View File

@ -71,8 +71,11 @@ class ProjectViewVM {
onRefreshed: (context) => _handleRefresh(context),
onClientPressed: (BuildContext context) => store
.dispatch(ViewClient(clientId: project.clientId, context: context)),
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(ProjectScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(ProjectScreen.route)) {
store.dispatch(UpdateCurrentRoute(ProjectScreen.route));
}
},
onActionSelected: (BuildContext context, EntityAction action) {
final localization = AppLocalization.of(context);
switch (action) {

View File

@ -64,8 +64,11 @@ class QuoteEditVM extends EntityEditVM {
invoice: quote,
invoiceItem: state.quoteUIState.editingItem,
origInvoice: store.state.quoteState.map[quote.id],
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(QuoteScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(QuoteScreen.route)) {
store.dispatch(UpdateCurrentRoute(QuoteViewScreen.route));
}
},
onSavePressed: (BuildContext context) {
final Completer<InvoiceEntity> completer = Completer<InvoiceEntity>();
store.dispatch(SaveQuoteRequest(completer: completer, quote: quote));

View File

@ -102,8 +102,11 @@ class QuoteViewVM extends EntityViewVM {
});
},
onRefreshed: (context) => _handleRefresh(context),
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(QuoteScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(QuoteScreen.route)) {
store.dispatch(UpdateCurrentRoute(QuoteScreen.route));
}
},
onClientPressed: (BuildContext context) {
store.dispatch(ViewClient(clientId: client.id, context: context));
},

View File

@ -66,7 +66,9 @@ class TaskEditVM {
store.dispatch(UpdateTask(task));
},
onBackPressed: () {
store.dispatch(UpdateCurrentRoute(TaskScreen.route));
if (state.uiState.currentRoute.contains(TaskScreen.route)) {
store.dispatch(UpdateCurrentRoute(TaskScreen.route));
}
},
onAddClientPressed: (context, completer) {
store.dispatch(EditClient(

View File

@ -66,8 +66,11 @@ class TaskViewVM {
store.dispatch(EditTask(task: task, context: context));
},
onRefreshed: (context) => _handleRefresh(context),
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(TaskScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(TaskScreen.route)) {
store.dispatch(UpdateCurrentRoute(TaskScreen.route));
}
},
onActionSelected: (BuildContext context, EntityAction action) {
final localization = AppLocalization.of(context);
switch (action) {

View File

@ -60,7 +60,9 @@ class StubEditVM {
store.dispatch(UpdateStub(stub));
},
onBackPressed: () {
store.dispatch(UpdateCurrentRoute(StubScreen.route));
if (state.uiState.currentRoute.contains(StubScreen.route)) {
store.dispatch(UpdateCurrentRoute(StubViewScreen.route));
}
},
onSavePressed: (BuildContext context) {
final Completer<StubEntity> completer = new Completer<StubEntity>();

View File

@ -66,8 +66,11 @@ class StubViewVM {
store.dispatch(EditStub(stub: stub, context: context));
},
onRefreshed: (context) => _handleRefresh(context),
onBackPressed: () =>
store.dispatch(UpdateCurrentRoute(StubScreen.route)),
onBackPressed: () {
if (state.uiState.currentRoute.contains(StubScreen.route)) {
store.dispatch(UpdateCurrentRoute(StubScreen.route));
}
},
onActionSelected: (BuildContext context, EntityAction action) {
final localization = AppLocalization.of(context);
switch (action) {