Navigate back to same selected city on servers page after editing a server.
This commit is contained in:
parent
ae3f096722
commit
d6df2a448d
@ -17,11 +17,12 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
private string selectedCity = "Eindhoven";
|
|
||||||
private List<string> cities = ServersRepository.GetCities();
|
private List<string> cities = ServersRepository.GetCities();
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public EventCallback<string> SelectCityCallBack { get; set; }
|
public EventCallback<string> SelectCityCallBack { get; set; }
|
||||||
|
[Parameter]
|
||||||
|
public string? selectedCity { get; set; } = "Eindhoven";
|
||||||
|
|
||||||
public void ClearSelection()
|
public void ClearSelection()
|
||||||
{
|
{
|
||||||
|
|||||||
@ -54,6 +54,6 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// An exception is raised when debugging from VS Code, but not when using dotnet watch.
|
// An exception is raised when debugging from VS Code, but not when using dotnet watch.
|
||||||
NavigationManager.NavigateTo("/servers");
|
NavigationManager.NavigateTo($"/servers/back_from/{this.server?.City}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -74,7 +74,7 @@ The navigation manager only will respond correctly if all its behaviours are the
|
|||||||
}
|
}
|
||||||
|
|
||||||
// An exception is raised when debugging from VS Code, but not when using dotnet watch.
|
// An exception is raised when debugging from VS Code, but not when using dotnet watch.
|
||||||
NavigationManager.NavigateTo("/servers");
|
NavigationManager.NavigateTo($"/servers/back_from/{this.server?.City}");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task OnBeforeInternalNavigation(LocationChangingContext context)
|
private async Task OnBeforeInternalNavigation(LocationChangingContext context)
|
||||||
|
|||||||
@ -1,10 +1,16 @@
|
|||||||
@page "/servers"
|
@page "/servers"
|
||||||
|
@page "/servers/back_from/{cityName}"
|
||||||
@using ServerManagement.Components.Controls
|
@using ServerManagement.Components.Controls
|
||||||
|
@inject NavigationManager NavigationManager
|
||||||
|
|
||||||
<h3>Servers</h3>
|
<h3>Servers</h3>
|
||||||
<br/>
|
<br/>
|
||||||
<br/>
|
<br/>
|
||||||
<CityListComponent @ref="cityListComponent" SelectCityCallBack="HandleCitySelection"></CityListComponent>
|
<CityListComponent
|
||||||
|
@ref="cityListComponent"
|
||||||
|
SelectCityCallBack="HandleCitySelection"
|
||||||
|
selectedCity="@this.selectedCity">
|
||||||
|
</CityListComponent>
|
||||||
<br/>
|
<br/>
|
||||||
<SearchBarComponent
|
<SearchBarComponent
|
||||||
@ref="searchBarComponent"
|
@ref="searchBarComponent"
|
||||||
@ -23,6 +29,8 @@
|
|||||||
</CascadingValue>
|
</CascadingValue>
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
|
[Parameter]
|
||||||
|
public string? CityName { get; set; }
|
||||||
private string selectedCity = "Eindhoven";
|
private string selectedCity = "Eindhoven";
|
||||||
private string searchFilter = "";
|
private string searchFilter = "";
|
||||||
private CityListComponent? cityListComponent;
|
private CityListComponent? cityListComponent;
|
||||||
@ -40,4 +48,16 @@
|
|||||||
this.searchFilter = searchFilter;
|
this.searchFilter = searchFilter;
|
||||||
cityListComponent?.ClearSelection();
|
cityListComponent?.ClearSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnAfterRender(bool firstRender)
|
||||||
|
{
|
||||||
|
if (firstRender)
|
||||||
|
{
|
||||||
|
if (NavigationManager.Uri.Contains("back_from") && !string.IsNullOrWhiteSpace(CityName))
|
||||||
|
{
|
||||||
|
selectedCity = CityName;
|
||||||
|
StateHasChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user