about summary refs log tree commit diff
path: root/MatrixUtils.Web/Classes/SessionStorageProviderService.cs
blob: ae0bb793acbc67cccce136d6719c71607b86e82c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
using Blazored.SessionStorage;
using LibMatrix.Interfaces.Services;

namespace MatrixUtils.Web.Classes;

public class SessionStorageProviderService : IStorageProvider {
    private readonly ISessionStorageService _sessionStorageService;

    public SessionStorageProviderService(ISessionStorageService sessionStorage) {
        _sessionStorageService = sessionStorage;
    }

    Task IStorageProvider.SaveAllChildrenAsync<T>(string key, T value) {
        throw new NotImplementedException();
    }

    Task<T?> IStorageProvider.LoadAllChildrenAsync<T>(string key) where T : default => throw new NotImplementedException();

    async Task IStorageProvider.SaveObjectAsync<T>(string key, T value) => await _sessionStorageService.SetItemAsync(key, value);

    async Task<T?> IStorageProvider.LoadObjectAsync<T>(string key) where T : default => await _sessionStorageService.GetItemAsync<T>(key);

    async Task<bool> IStorageProvider.ObjectExistsAsync(string key) => await _sessionStorageService.ContainKeyAsync(key);

    async Task<List<string>> IStorageProvider.GetAllKeysAsync() => (await _sessionStorageService.KeysAsync()).ToList();

    async Task IStorageProvider.DeleteObjectAsync(string key) => await _sessionStorageService.RemoveItemAsync(key);
}