mirror of
https://github.com/DrMboga/WotBlitzStatisticsBlazor.git
synced 2026-10-21 02:17:20 +02:00
feat: selected realm stored in browser's local storage
This commit is contained in:
1 parent
4fb56c3b16
commit
46ed757dcb
10 files changed
+79
-5
No files matched your search
@@ -0,0 +1,15 @@
|
||||
using MediatR;
|
||||
using WotBlitzStatisticsPro.Blazor.GraphQl;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Messages
|
||||
{
|
||||
public class ChangeCurrentRealmTypeMessage: INotification
|
||||
{
|
||||
public RealmType RealmType { get; }
|
||||
|
||||
public ChangeCurrentRealmTypeMessage(RealmType realmType)
|
||||
{
|
||||
RealmType = realmType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
namespace WotBlitzStatisticsPro.Blazor.Model
|
||||
using WotBlitzStatisticsPro.Blazor.GraphQl;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Model
|
||||
{
|
||||
public class UserSettings
|
||||
{
|
||||
public const string UserSettingsLocalStorageKey = "user-settings";
|
||||
|
||||
public string Culture { get; set; } = "en-US";
|
||||
|
||||
public RealmType RealmType { get; set; } = RealmType.Eu;
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@
|
||||
<span style="color: @Constants.ClanTagColor;"> [<span style="font-weight: bolder;">@Player.ClanTag</span>]</span>
|
||||
}
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="row" title="@Localize["Win rate"]">
|
||||
<span style="font-size: 12px; color: @Player.WinRate.ScaleColor()"> <RadzenIcon Icon="flag" Style="height: 15px;" /> @Player.WinRate%</span>
|
||||
</div>
|
||||
<div class="row" title="@Localize["Battles"]">
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
<RadzenDropDown @bind-Value=@CurrentRealmType
|
||||
Data=@Realms
|
||||
ValueProperty="RealmType"
|
||||
Style="width: 87px">
|
||||
Style="width: 87px"
|
||||
Change="@OnRealmChanged">
|
||||
<Template>
|
||||
<img src="@(((RealmSelector) context).RealmImage)" style="height: 27px"/>
|
||||
</Template>
|
||||
|
||||
@@ -26,6 +26,9 @@ namespace WotBlitzStatisticsPro.Blazor.Pages
|
||||
[Inject]
|
||||
public IGraphQlBackendService GraphQlBackendService { get; set; }
|
||||
|
||||
[Inject]
|
||||
public ILocalStorageService LocalStorageService { get; set; }
|
||||
|
||||
[Parameter]
|
||||
public DialogType DialogType { get; set; }
|
||||
|
||||
@@ -52,6 +55,23 @@ namespace WotBlitzStatisticsPro.Blazor.Pages
|
||||
|
||||
}
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
var settings = await LocalStorageService.ReadSettings();
|
||||
CurrentRealmType = settings.RealmType;
|
||||
|
||||
await base.OnInitializedAsync();
|
||||
}
|
||||
|
||||
public async Task OnRealmChanged(object value)
|
||||
{
|
||||
if (value is RealmType realm)
|
||||
{
|
||||
await Mediator.Publish(new ChangeCurrentRealmTypeMessage(realm));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public async Task OnSearchTextChange(string value)
|
||||
{
|
||||
if (DialogType == DialogType.FindPlayer && value.Length < 3)
|
||||
|
||||
@@ -117,6 +117,9 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Battles" xml:space="preserve">
|
||||
<value>Schlachten</value>
|
||||
</data>
|
||||
<data name="Created" xml:space="preserve">
|
||||
<value>Erstellt</value>
|
||||
</data>
|
||||
@@ -129,6 +132,9 @@
|
||||
<data name="hours ago" xml:space="preserve">
|
||||
<value>vor Stunden</value>
|
||||
</data>
|
||||
<data name="Last battle" xml:space="preserve">
|
||||
<value>Letzte Schlacht</value>
|
||||
</data>
|
||||
<data name="Login with WG.net ID" xml:space="preserve">
|
||||
<value>Anmelden mit WG.net-ID</value>
|
||||
</data>
|
||||
@@ -153,6 +159,9 @@
|
||||
<data name="Welcome to WOT Blitz statistics application!" xml:space="preserve">
|
||||
<value>Willkommen bei der WOT Blitz statistics!</value>
|
||||
</data>
|
||||
<data name="Win rate" xml:space="preserve">
|
||||
<value>Gewinnrate</value>
|
||||
</data>
|
||||
<data name="years ago" xml:space="preserve">
|
||||
<value>vor Jahren</value>
|
||||
</data>
|
||||
|
||||
@@ -117,6 +117,9 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="Battles" xml:space="preserve">
|
||||
<value>Количество боёв</value>
|
||||
</data>
|
||||
<data name="Created" xml:space="preserve">
|
||||
<value>Создан</value>
|
||||
</data>
|
||||
@@ -129,6 +132,9 @@
|
||||
<data name="hours ago" xml:space="preserve">
|
||||
<value>часов назад</value>
|
||||
</data>
|
||||
<data name="Last battle" xml:space="preserve">
|
||||
<value>Последний бой</value>
|
||||
</data>
|
||||
<data name="Login with WG.net ID" xml:space="preserve">
|
||||
<value>Войти с WG.net ID</value>
|
||||
</data>
|
||||
@@ -153,6 +159,9 @@
|
||||
<data name="Welcome to WOT Blitz statistics application!" xml:space="preserve">
|
||||
<value>Добро пожаловать в WOT Blitz statistics!</value>
|
||||
</data>
|
||||
<data name="Win rate" xml:space="preserve">
|
||||
<value>Процент побед</value>
|
||||
</data>
|
||||
<data name="years ago" xml:space="preserve">
|
||||
<value>лет назад</value>
|
||||
</data>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Threading.Tasks;
|
||||
using WotBlitzStatisticsPro.Blazor.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
{
|
||||
@@ -7,5 +8,7 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
Task SetItemAsync<T>(string key, T item);
|
||||
|
||||
Task<T> GetItemAsync<T>(string key);
|
||||
|
||||
Task<UserSettings> ReadSettings();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ using WotBlitzStatisticsPro.Blazor.Model;
|
||||
|
||||
namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
{
|
||||
public class LocalStorageService: ILocalStorageService, INotificationHandler<ChangeCurrentCultureMessage>
|
||||
public class LocalStorageService: ILocalStorageService, INotificationHandler<ChangeCurrentCultureMessage>, INotificationHandler<ChangeCurrentRealmTypeMessage>
|
||||
{
|
||||
private readonly IJSRuntime _jsRuntime;
|
||||
private readonly NavigationManager _navigationManager;
|
||||
@@ -36,12 +36,24 @@ namespace WotBlitzStatisticsPro.Blazor.Services
|
||||
: JsonSerializer.Deserialize<T>(json);
|
||||
}
|
||||
|
||||
public async Task<UserSettings> ReadSettings()
|
||||
{
|
||||
return await GetItemAsync<UserSettings>(UserSettings.UserSettingsLocalStorageKey) ?? new UserSettings();
|
||||
}
|
||||
|
||||
public async Task Handle(ChangeCurrentCultureMessage notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var currentSettings = await GetItemAsync<UserSettings>(UserSettings.UserSettingsLocalStorageKey) ?? new UserSettings();
|
||||
var currentSettings = await ReadSettings();
|
||||
currentSettings.Culture = notification.CultureName;
|
||||
await SetItemAsync(UserSettings.UserSettingsLocalStorageKey, currentSettings);
|
||||
_navigationManager.NavigateTo(_navigationManager.Uri, forceLoad: true);
|
||||
}
|
||||
|
||||
public async Task Handle(ChangeCurrentRealmTypeMessage notification, CancellationToken cancellationToken)
|
||||
{
|
||||
var currentSettings = await ReadSettings();
|
||||
currentSettings.RealmType = notification.RealmType;
|
||||
await SetItemAsync(UserSettings.UserSettingsLocalStorageKey, currentSettings);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@
|
||||
<title>WotBlitzStatisticsPro</title>
|
||||
<base href="/" />
|
||||
<link rel="stylesheet" href="_content/Radzen.Blazor/css/dark.css">
|
||||
<!--<link rel="stylesheet" href="_content/Radzen.Blazor/css/default.css">-->
|
||||
<link href="css/app.css" rel="stylesheet" />
|
||||
<link href="WotBlitzStatisticsPro.Blazor.styles.css" rel="stylesheet" />
|
||||
<link href="manifest.json" rel="manifest" />
|
||||
|
||||
Reference in new issue
Block a user