MRB webassembly

This commit is contained in:
Chase Tucker
2024-05-13 14:33:27 -07:00
parent ba8d92ea01
commit 9b7e3ef897
109 changed files with 11731 additions and 1024 deletions

View File

@ -0,0 +1,49 @@
using System.Text.Json;
using System.Text.Json.Serialization;
using Microsoft.JSInterop;
namespace MesaFabApproval.Client.Services;
public interface ILocalStorageService {
Task AddItem(string key, string value);
Task AddItem<T>(string key, T value);
Task RemoveItem(string key);
Task<string> GetItem(string key);
Task<T?> GetItem<T>(string key);
}
public class LocalStorageService : ILocalStorageService {
private readonly IJSRuntime _jsRuntime;
public LocalStorageService(IJSRuntime jsRuntime) {
_jsRuntime = jsRuntime;
}
public async Task AddItem(string key, string value) {
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", key, value);
}
public async Task AddItem<T>(string key, T value) {
string item = JsonSerializer.Serialize(value);
await _jsRuntime.InvokeVoidAsync("localStorage.setItem", key, item);
}
public async Task RemoveItem(string key) {
await _jsRuntime.InvokeVoidAsync("localStorage.removeItem", key);
}
public async Task<string> GetItem(string key) {
return await _jsRuntime.InvokeAsync<string>("localStorage.getItem", key);
}
public async Task<T?> GetItem<T>(string key) {
string item = await _jsRuntime.InvokeAsync<string>("localStorage.getItem", key);
JsonSerializerOptions jsonSerializerOptions = new() {
PropertyNameCaseInsensitive = true
};
return JsonSerializer.Deserialize<T>(item, jsonSerializerOptions);
}
}