1
0
mirror of synced 2024-12-18 09:15:54 +01:00
GC-local-server-rewrite/WebUI/Pages/Cards.razor.cs

56 lines
1.5 KiB
C#
Raw Normal View History

using Shared.Dto.Api;
2023-02-21 15:45:51 +01:00
using Throw;
using WebUI.Pages.Dialogs;
2023-02-16 17:38:01 +01:00
namespace WebUI.Pages;
public partial class Cards
{
[Inject]
2023-02-17 18:29:20 +01:00
public required HttpClient Client { get; set; }
[Inject]
public required IDialogService DialogService { get; set; }
2023-02-16 17:38:01 +01:00
2023-02-21 15:45:51 +01:00
[Inject]
public required ILogger<Cards> Logger { get; set; }
2023-02-16 17:38:01 +01:00
private List<ClientCardDto>? CardDtos { get; set; }
private string ErrorMessage { get; set; } = string.Empty;
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
2023-02-16 17:38:01 +01:00
var result = await Client.GetFromJsonAsync<ServiceResult<List<ClientCardDto>>>("api/Profiles");
2023-02-21 15:45:51 +01:00
result.ThrowIfNull();
Logger.LogInformation("Result: {Result}", result.Succeeded);
2023-02-16 17:38:01 +01:00
if (!result.Succeeded)
{
ErrorMessage = result.Error!.Message;
return;
}
CardDtos = result.Data;
}
2023-02-17 18:29:20 +01:00
private async Task OnEditPlayerNameClicked(ClientCardDto card)
{
var options = new DialogOptions
{
CloseOnEscapeKey = false,
DisableBackdropClick = true,
FullWidth = true
};
var parameters = new DialogParameters { { "Data", card } };
var dialog = await DialogService.ShowAsync<ChangePlayerNameDialog>("Favorite", parameters, options);
2023-02-21 15:45:51 +01:00
// ReSharper disable once UnusedVariable
2023-02-17 18:29:20 +01:00
var result = await dialog.Result;
if (!result.Canceled)
{
StateHasChanged();
}
2023-02-17 18:29:20 +01:00
}
2023-02-16 17:38:01 +01:00
}