From 19b54a0f640ba09ad2d1664c0e8d09470dd14db8 Mon Sep 17 00:00:00 2001 From: itbeard Date: Sun, 26 Jun 2022 18:25:21 +0200 Subject: [PATCH] Update behaviour of Back Button --- Pds/Pds.Web/Pages/BasePageComponent.cs | 14 +++++++++++++- Pds/Pds.Web/Pages/Bills/Create.razor | 2 +- Pds/Pds.Web/Pages/Bills/Edit.razor | 2 +- Pds/Pds.Web/Pages/Brands/Create.razor | 2 +- Pds/Pds.Web/Pages/Brands/Edit.razor | 2 +- Pds/Pds.Web/Pages/Clients/Create.razor | 2 +- Pds/Pds.Web/Pages/Clients/Edit.razor | 2 +- Pds/Pds.Web/Pages/Content/Create.razor | 2 +- Pds/Pds.Web/Pages/Content/Edit.razor | 2 +- Pds/Pds.Web/Pages/Content/Pay.razor | 2 +- Pds/Pds.Web/Pages/Costs/Create.razor | 2 +- Pds/Pds.Web/Pages/Costs/Edit.razor | 2 +- Pds/Pds.Web/Pages/Gifts/Create.razor | 2 +- Pds/Pds.Web/Pages/Gifts/Edit.razor | 2 +- Pds/Pds.Web/Pages/Persons/Create.razor | 2 +- Pds/Pds.Web/Pages/Persons/Edit.razor | 2 +- Pds/Pds.Web/Pages/Settings/Edit.razor | 1 + 17 files changed, 29 insertions(+), 16 deletions(-) diff --git a/Pds/Pds.Web/Pages/BasePageComponent.cs b/Pds/Pds.Web/Pages/BasePageComponent.cs index a20f06f4..34d1e73e 100644 --- a/Pds/Pds.Web/Pages/BasePageComponent.cs +++ b/Pds/Pds.Web/Pages/BasePageComponent.cs @@ -27,12 +27,24 @@ protected override void OnInitialized() base.OnInitialized(); } - protected void GoBack() + protected void GoBack(string defaultBackPath) { _pageState.RemoveCurrent(_navManager.Uri); if (_pageState.CanGoBack()) { _navManager.NavigateTo(_pageState.PreviousPage()); } + else + { + if (!string.IsNullOrEmpty(defaultBackPath)) + { + _navManager.NavigateTo(defaultBackPath); + } + } + } + + protected void GoBack() + { + GoBack(null); } } \ No newline at end of file diff --git a/Pds/Pds.Web/Pages/Bills/Create.razor b/Pds/Pds.Web/Pages/Bills/Create.razor index beef8845..aacdbc09 100644 --- a/Pds/Pds.Web/Pages/Bills/Create.razor +++ b/Pds/Pds.Web/Pages/Bills/Create.razor @@ -184,7 +184,7 @@ else isCreateButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/bills"); + GoBack("/bills"); } else { diff --git a/Pds/Pds.Web/Pages/Bills/Edit.razor b/Pds/Pds.Web/Pages/Bills/Edit.razor index 5dae2b10..3a0e9008 100644 --- a/Pds/Pds.Web/Pages/Bills/Edit.razor +++ b/Pds/Pds.Web/Pages/Bills/Edit.razor @@ -204,7 +204,7 @@ else isSaveButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/bills"); + GoBack("/bills"); } else { diff --git a/Pds/Pds.Web/Pages/Brands/Create.razor b/Pds/Pds.Web/Pages/Brands/Create.razor index 48082249..5ee060f1 100644 --- a/Pds/Pds.Web/Pages/Brands/Create.razor +++ b/Pds/Pds.Web/Pages/Brands/Create.razor @@ -71,7 +71,7 @@ else if (result.IsSuccessStatusCode) { await localStorage.ClearAsync(); - NavigationManager.NavigateTo("/brands"); + GoBack("/brands"); } else { diff --git a/Pds/Pds.Web/Pages/Brands/Edit.razor b/Pds/Pds.Web/Pages/Brands/Edit.razor index e5be53ef..bf6f821c 100644 --- a/Pds/Pds.Web/Pages/Brands/Edit.razor +++ b/Pds/Pds.Web/Pages/Brands/Edit.razor @@ -77,7 +77,7 @@ else if (result.IsSuccessStatusCode) { await localStorage.ClearAsync(); - NavigationManager.NavigateTo("/brands"); + GoBack("/brands"); } else { diff --git a/Pds/Pds.Web/Pages/Clients/Create.razor b/Pds/Pds.Web/Pages/Clients/Create.razor index dda51c10..518aa15b 100644 --- a/Pds/Pds.Web/Pages/Clients/Create.razor +++ b/Pds/Pds.Web/Pages/Clients/Create.razor @@ -69,7 +69,7 @@ else isCreateButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/clients"); + GoBack("/clients"); } else { diff --git a/Pds/Pds.Web/Pages/Clients/Edit.razor b/Pds/Pds.Web/Pages/Clients/Edit.razor index 904dba3c..1dac93e6 100644 --- a/Pds/Pds.Web/Pages/Clients/Edit.razor +++ b/Pds/Pds.Web/Pages/Clients/Edit.razor @@ -75,7 +75,7 @@ else isCreateButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/clients"); + GoBack("/clients"); } else { diff --git a/Pds/Pds.Web/Pages/Content/Create.razor b/Pds/Pds.Web/Pages/Content/Create.razor index 79aa2731..7dbd5ddd 100644 --- a/Pds/Pds.Web/Pages/Content/Create.razor +++ b/Pds/Pds.Web/Pages/Content/Create.razor @@ -204,7 +204,7 @@ else isCreateButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/content"); + GoBack("/content"); } else { diff --git a/Pds/Pds.Web/Pages/Content/Edit.razor b/Pds/Pds.Web/Pages/Content/Edit.razor index f38d53a0..2a8a0100 100644 --- a/Pds/Pds.Web/Pages/Content/Edit.razor +++ b/Pds/Pds.Web/Pages/Content/Edit.razor @@ -199,7 +199,7 @@ else isEditButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/content"); + GoBack("/content"); } else { diff --git a/Pds/Pds.Web/Pages/Content/Pay.razor b/Pds/Pds.Web/Pages/Content/Pay.razor index d4ac927d..15324ba3 100644 --- a/Pds/Pds.Web/Pages/Content/Pay.razor +++ b/Pds/Pds.Web/Pages/Content/Pay.razor @@ -113,7 +113,7 @@ else { isCreateButtonDisabled = true; await ApiClient.Put(TokenProvider, $"bills/{content.Bill.Id}/pay", paymentPayload); - NavigationManager.NavigateTo("/content"); + GoBack("/content"); } } diff --git a/Pds/Pds.Web/Pages/Costs/Create.razor b/Pds/Pds.Web/Pages/Costs/Create.razor index 95c3d25f..7afd2dd9 100644 --- a/Pds/Pds.Web/Pages/Costs/Create.razor +++ b/Pds/Pds.Web/Pages/Costs/Create.razor @@ -115,7 +115,7 @@ else isCreateButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/costs"); + GoBack("/costs"); } else { diff --git a/Pds/Pds.Web/Pages/Costs/Edit.razor b/Pds/Pds.Web/Pages/Costs/Edit.razor index 75c7aaf3..f86c9a64 100644 --- a/Pds/Pds.Web/Pages/Costs/Edit.razor +++ b/Pds/Pds.Web/Pages/Costs/Edit.razor @@ -129,7 +129,7 @@ else isSaveButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/costs"); + GoBack("/costs"); } else { diff --git a/Pds/Pds.Web/Pages/Gifts/Create.razor b/Pds/Pds.Web/Pages/Gifts/Create.razor index 51772390..0d6df3d5 100644 --- a/Pds/Pds.Web/Pages/Gifts/Create.razor +++ b/Pds/Pds.Web/Pages/Gifts/Create.razor @@ -148,7 +148,7 @@ else isCreateButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/gifts"); + GoBack("/gifts"); } else { diff --git a/Pds/Pds.Web/Pages/Gifts/Edit.razor b/Pds/Pds.Web/Pages/Gifts/Edit.razor index 74548ed3..aa972433 100644 --- a/Pds/Pds.Web/Pages/Gifts/Edit.razor +++ b/Pds/Pds.Web/Pages/Gifts/Edit.razor @@ -164,7 +164,7 @@ else isSaveButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/gifts"); + GoBack("/gifts"); } else { diff --git a/Pds/Pds.Web/Pages/Persons/Create.razor b/Pds/Pds.Web/Pages/Persons/Create.razor index 0cfeb545..c2e0a417 100644 --- a/Pds/Pds.Web/Pages/Persons/Create.razor +++ b/Pds/Pds.Web/Pages/Persons/Create.razor @@ -147,7 +147,7 @@ else isCreateButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/persons"); + GoBack("/persons"); } else { diff --git a/Pds/Pds.Web/Pages/Persons/Edit.razor b/Pds/Pds.Web/Pages/Persons/Edit.razor index c4a54ce9..aa9bcce6 100644 --- a/Pds/Pds.Web/Pages/Persons/Edit.razor +++ b/Pds/Pds.Web/Pages/Persons/Edit.razor @@ -162,7 +162,7 @@ else isSaveButtonDisabled = false; if (result.IsSuccessStatusCode) { - NavigationManager.NavigateTo("/persons"); + GoBack("/persons"); } else { diff --git a/Pds/Pds.Web/Pages/Settings/Edit.razor b/Pds/Pds.Web/Pages/Settings/Edit.razor index 440c592f..52b1e09e 100644 --- a/Pds/Pds.Web/Pages/Settings/Edit.razor +++ b/Pds/Pds.Web/Pages/Settings/Edit.razor @@ -79,6 +79,7 @@ else isCreateButtonDisabled = false; if (result.IsSuccessStatusCode) { + GoBack("/persons"); NavigationManager.NavigateTo("/settings", forceLoad: true); } else