Interop local storage APIs should be generic

This commit is contained in:
hishamco 2020-12-03 13:37:18 +03:00
parent fa3cc48fd0
commit 1b3cc2c44e
4 changed files with 12 additions and 12 deletions

View File

@ -94,7 +94,7 @@ namespace Oqtane.Client
var host = builder.Build();
var jsRuntime = host.Services.GetRequiredService<IJSRuntime>();
var interop = new Interop(jsRuntime);
var culture = await interop.getCulture();
var culture = await interop.GetLocalStorage("OqtaneCulture");
if (culture != null)
{
var cultureInfo = CultureInfo.GetCultureInfo(culture);

View File

@ -26,7 +26,7 @@
protected override async Task OnParametersSetAsync()
{
var interop = new Interop(JSRuntime);
_selectedCulture = await interop.getCulture();
_selectedCulture = await interop.GetLocalStorage("OqtaneCulture");
_supportedCultures = await LocalizationService.GetSupportedCultures();
}
@ -35,7 +35,7 @@
if (culture != CultureInfo.CurrentUICulture.Name)
{
var interop = new Interop(JSRuntime);
await interop.setCulture(culture);
await interop.SetLocalStorage("OqtaneCulture", culture);
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true);
}

View File

@ -234,13 +234,13 @@ namespace Oqtane.UI
}
}
public async Task<string> getCulture()
public async Task<string> GetLocalStorage(string name)
{
try
{
var culture = await _jsRuntime.InvokeAsync<string>("Oqtane.Interop.getCulture");
var value = await _jsRuntime.InvokeAsync<string>("Oqtane.Interop.getLocalStorage", name);
return culture;
return value;
}
catch
{
@ -248,11 +248,11 @@ namespace Oqtane.UI
}
}
public Task setCulture(string culture)
public Task SetLocalStorage(string name, string value)
{
try
{
_jsRuntime.InvokeVoidAsync("Oqtane.Interop.setCulture", culture);
_jsRuntime.InvokeVoidAsync("Oqtane.Interop.setLocalStorage", name, value);
return Task.CompletedTask;
}

View File

@ -363,10 +363,10 @@ Oqtane.Interop = {
window.location.href = url;
}, wait * 1000);
},
getCulture: function () {
return window.localStorage['OqtaneCulture'];
getLocalStorage: function (name) {
return window.localStorage[name];
},
setCulture: function (culture) {
window.localStorage['OqtaneCulture'] = culture;
setLocalStorage: function (name, value) {
window.localStorage[name] = value;
}
};