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 host = builder.Build();
var jsRuntime = host.Services.GetRequiredService<IJSRuntime>(); var jsRuntime = host.Services.GetRequiredService<IJSRuntime>();
var interop = new Interop(jsRuntime); var interop = new Interop(jsRuntime);
var culture = await interop.getCulture(); var culture = await interop.GetLocalStorage("OqtaneCulture");
if (culture != null) if (culture != null)
{ {
var cultureInfo = CultureInfo.GetCultureInfo(culture); var cultureInfo = CultureInfo.GetCultureInfo(culture);

View File

@ -26,7 +26,7 @@
protected override async Task OnParametersSetAsync() protected override async Task OnParametersSetAsync()
{ {
var interop = new Interop(JSRuntime); var interop = new Interop(JSRuntime);
_selectedCulture = await interop.getCulture(); _selectedCulture = await interop.GetLocalStorage("OqtaneCulture");
_supportedCultures = await LocalizationService.GetSupportedCultures(); _supportedCultures = await LocalizationService.GetSupportedCultures();
} }
@ -35,7 +35,7 @@
if (culture != CultureInfo.CurrentUICulture.Name) if (culture != CultureInfo.CurrentUICulture.Name)
{ {
var interop = new Interop(JSRuntime); var interop = new Interop(JSRuntime);
await interop.setCulture(culture); await interop.SetLocalStorage("OqtaneCulture", culture);
NavigationManager.NavigateTo(NavigationManager.Uri, forceLoad: true); 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 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 catch
{ {
@ -248,11 +248,11 @@ namespace Oqtane.UI
} }
} }
public Task setCulture(string culture) public Task SetLocalStorage(string name, string value)
{ {
try try
{ {
_jsRuntime.InvokeVoidAsync("Oqtane.Interop.setCulture", culture); _jsRuntime.InvokeVoidAsync("Oqtane.Interop.setLocalStorage", name, value);
return Task.CompletedTask; return Task.CompletedTask;
} }

View File

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