Refactored / removed JavaScript. Replaced BlazoredLocalStorage.

This commit is contained in:
Ed Charbeneau 2020-08-14 13:13:03 -04:00
Родитель b18a71d89e
Коммит af781cdd4e
4 изменённых файлов: 8 добавлений и 18 удалений

Просмотреть файл

@ -1,12 +1,12 @@
@using System.Globalization
@inject IJSRuntime js
@inject NavigationManager NavigationManager
@inject ILocalStorageService LocalStorage
<div style="margin-bottom: 20px;">
<TelerikDropDownList Data="@Cultures"
Value="@SelectedCulture"
ValueChanged="@((string value) => { OnValueChanged(value); })"
ValueChanged="@((string value) => OnValueChanged(value) )"
TextField="@nameof(CultureData.Text)"
ValueField="@nameof(CultureData.Value)">
</TelerikDropDownList>
@ -29,18 +29,18 @@
public string SelectedCulture { get; set; }
public void OnValueChanged(string eventArgs)
public async Task OnValueChanged(string eventArgs)
{
SelectedCulture = eventArgs;
SetCulture(eventArgs);
await SetCulture(eventArgs);
}
public void SetCulture(string culture)
public async Task SetCulture(string culture)
{
if (CultureInfo.CurrentCulture.Name != culture)
{
js.InvokeVoidAsync("blazorCulture.set", culture);
await LocalStorage.SetItemAsync("BlazorCulture", culture);
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
}
@ -48,7 +48,7 @@
public async Task GetCulture()
{
var value = await js.InvokeAsync<string>("blazorCulture.get");
var value = await LocalStorage.GetItemAsStringAsync("BlazorCulture");
if (string.IsNullOrEmpty(value))
{
value = "en-US";

Просмотреть файл

@ -97,7 +97,7 @@
{
Expanded = value;
await LocalStorage.SetItemAsync<bool>("drawerState", value);
await LocalStorage.SetItemAsync("drawerState", value);
}
protected override async Task OnInitializedAsync()

Просмотреть файл

@ -25,7 +25,6 @@
</div>
<script src="_content/Microsoft.AspNetCore.Components.WebAssembly.Authentication/AuthenticationService.js"></script>
<script src="_framework/blazor.webassembly.js"></script>
<script src="js/blazorCulture.js"></script>
<script src="js/themeChooser.js"></script>
<script>
window.themeChooser.init();

Просмотреть файл

@ -1,9 +0,0 @@
window.blazorCulture = {
get: () => {
return window.localStorage['BlazorCulture'];
},
set: (value) => {
window.localStorage['BlazorCulture'] = value;
}
};