2023-02-22 17:35:59 +01:00
|
|
|
|
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-21 19:55:32 +01:00
|
|
|
|
|
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();
|
|
|
|
|
|
2023-02-21 19:55:32 +01:00
|
|
|
|
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;
|
2023-02-21 19:55:32 +01:00
|
|
|
|
if (!result.Canceled)
|
|
|
|
|
{
|
|
|
|
|
StateHasChanged();
|
|
|
|
|
}
|
2023-02-17 18:29:20 +01:00
|
|
|
|
}
|
2023-02-16 17:38:01 +01:00
|
|
|
|
}
|