Files
game-ideas/src/GameIdeas/Client/GameIdeas.BlazorApp/Pages/Games/Components/GameBase.cs
Maxime Adler ab773f8b71
All checks were successful
Game Ideas build for PR / build_test (pull_request) Successful in 1m9s
Fix wrong comportment
2025-05-13 14:03:42 +02:00

60 lines
1.9 KiB
C#

using GameIdeas.BlazorApp.Shared.Components.Select;
using GameIdeas.BlazorApp.Shared.Components.Select.Models;
using GameIdeas.Resources;
using GameIdeas.Shared.Dto;
using Microsoft.AspNetCore.Components;
namespace GameIdeas.BlazorApp.Pages.Games.Components;
public class GameBase : ComponentBase
{
[Parameter] public GameDto GameDto { get; set; } = new();
[Parameter] public EventCallback<GameDto> OnDelete { get; set; } = new();
[Parameter] public EventCallback<GameDto> OnEdit { get; set; } = new();
[Inject] public NavigationManager NavigationManager { get; set; } = default!;
protected SelectParams<DetailOptions, object> SelectParams = default!;
protected Select<DetailOptions, object>? SelectOption;
protected override void OnInitialized()
{
SelectParams = new()
{
Items = [DetailOptions.Detail, DetailOptions.Edit, DetailOptions.Delete],
GetItemLabel = GetDetailOptionsLabel
};
}
protected async Task HandlerSelectValuesChanged(IEnumerable<DetailOptions> detailOptions)
{
var option = detailOptions.First();
switch (option)
{
case DetailOptions.Detail:
NavigationManager.NavigateTo($"/Detail/{GameDto.Id}");
break;
case DetailOptions.Edit:
await OnEdit.InvokeAsync(GameDto);
break;
case DetailOptions.Delete:
await OnDelete.InvokeAsync(GameDto);
break;
default:
break;
}
SelectOption?.Close();
}
private string GetDetailOptionsLabel(DetailOptions options)
{
return options switch
{
DetailOptions.Detail => ResourcesKey.Detail,
DetailOptions.Edit => ResourcesKey.Edit,
DetailOptions.Delete => ResourcesKey.Delete,
_ => ResourcesKey.Unknown
};
}
}