Navigate back to same selected city on servers page after editing a server.
This commit is contained in:
parent
ae3f096722
commit
d6df2a448d
@ -10,18 +10,19 @@
|
||||
city="@city"
|
||||
selectedCity="@this.selectedCity"
|
||||
SelectCityCallBack="HandleCitySelection">
|
||||
</CityComponent>
|
||||
</CityComponent>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
|
||||
@code {
|
||||
private string selectedCity = "Eindhoven";
|
||||
private List<string> cities = ServersRepository.GetCities();
|
||||
|
||||
[Parameter]
|
||||
public EventCallback<string> SelectCityCallBack { get; set; }
|
||||
[Parameter]
|
||||
public string? selectedCity { get; set; } = "Eindhoven";
|
||||
|
||||
public void ClearSelection()
|
||||
{
|
||||
|
||||
@ -54,6 +54,6 @@
|
||||
}
|
||||
|
||||
// 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.
|
||||
NavigationManager.NavigateTo("/servers");
|
||||
NavigationManager.NavigateTo($"/servers/back_from/{this.server?.City}");
|
||||
}
|
||||
|
||||
private async Task OnBeforeInternalNavigation(LocationChangingContext context)
|
||||
|
||||
@ -1,10 +1,16 @@
|
||||
@page "/servers"
|
||||
@page "/servers/back_from/{cityName}"
|
||||
@using ServerManagement.Components.Controls
|
||||
@inject NavigationManager NavigationManager
|
||||
|
||||
<h3>Servers</h3>
|
||||
<br/>
|
||||
<br/>
|
||||
<CityListComponent @ref="cityListComponent" SelectCityCallBack="HandleCitySelection"></CityListComponent>
|
||||
<CityListComponent
|
||||
@ref="cityListComponent"
|
||||
SelectCityCallBack="HandleCitySelection"
|
||||
selectedCity="@this.selectedCity">
|
||||
</CityListComponent>
|
||||
<br/>
|
||||
<SearchBarComponent
|
||||
@ref="searchBarComponent"
|
||||
@ -23,6 +29,8 @@
|
||||
</CascadingValue>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string? CityName { get; set; }
|
||||
private string selectedCity = "Eindhoven";
|
||||
private string searchFilter = "";
|
||||
private CityListComponent? cityListComponent;
|
||||
@ -40,4 +48,16 @@
|
||||
this.searchFilter = searchFilter;
|
||||
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