Files
WotBlitzStatisticsBlazor/WotBlitzStatisticsPro.Blazor/Pages/PlayerInfoLayoutBase.cs
T

57 lines
1.9 KiB
C#
Raw Normal View History

using System.Collections.Generic;
using System.Threading.Tasks;
2021-05-28 15:27:36 +02:00
using Microsoft.AspNetCore.Components;
2021-07-21 15:44:14 +02:00
using Microsoft.Extensions.Localization;
2021-05-28 15:27:36 +02:00
using WotBlitzStatisticsPro.Blazor.GraphQl;
2021-09-01 17:35:40 +02:00
using WotBlitzStatisticsPro.Blazor.Model;
2021-05-28 15:27:36 +02:00
using WotBlitzStatisticsPro.Blazor.Services;
namespace WotBlitzStatisticsPro.Blazor.Pages
{
public class PlayerInfoLayoutBase: ComponentBase
{
2021-05-28 15:27:36 +02:00
[Inject]
public IGraphQlBackendService GraphQlBackendService { get; set; }
[Inject]
public ILocalStorageService LocalStorageService { get; set; }
2021-07-21 15:44:14 +02:00
[Inject]
public IStringLocalizer<App> Localize { get; set; }
2021-09-02 18:43:00 +02:00
[Inject]
public INotificationsService Notifications { get; set; }
2021-07-21 15:44:14 +02:00
[Parameter]
public long AccountId { get; set; }
2021-05-28 15:27:36 +02:00
public RealmType CurrentRealmType { get; set; } = RealmType.Eu;
2021-06-04 15:35:53 +02:00
public IAccount AccountInfo { get; set; }
2021-05-28 15:27:36 +02:00
2021-06-04 15:35:53 +02:00
public IReadOnlyList<ISection> AchievementsBySection { get; set; }
2021-05-28 15:27:36 +02:00
protected override async Task OnInitializedAsync()
{
2021-09-01 17:35:40 +02:00
var loggedInInfo = await LocalStorageService.GetItemAsync<LoginInfo>(Constants.LoginInfoLocalStorageKey);
2021-05-28 15:27:36 +02:00
var settings = await LocalStorageService.ReadSettings();
CurrentRealmType = settings.RealmType;
2021-09-02 09:32:47 +02:00
2021-09-02 18:43:00 +02:00
try
2021-09-01 17:35:40 +02:00
{
2021-09-02 18:43:00 +02:00
// Maybe add refresh button instead of calling mutation each time
if(loggedInInfo != null && loggedInInfo.AccountId == AccountId)
{
await GraphQlBackendService.CollectPlayerInfo(AccountId, CurrentRealmType, loggedInInfo.AccessToken);
}
2021-09-02 09:32:47 +02:00
2021-09-02 18:43:00 +02:00
(AccountInfo, AchievementsBySection) = await GraphQlBackendService.GetPlayerInfo(AccountId, CurrentRealmType);
}
catch (System.Exception e)
{
Notifications.ReportError("Can not get data from backend", e.Message);
}
2021-05-28 15:27:36 +02:00
}
}
}