1
0

Navigate back to same selected city on servers page after editing a server.

This commit is contained in:
Kevin Matsubara 2025-03-29 19:00:01 +01:00
parent ae3f096722
commit d6df2a448d
4 changed files with 26 additions and 5 deletions

View File

@ -17,11 +17,12 @@
}
@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()
{

View File

@ -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}");
}
}

View File

@ -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)

View File

@ -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();
}
}
}
}