[frontend/core] Add settings service

This commit is contained in:
Lilian 2024-11-26 01:59:27 +01:00
parent b2b206f065
commit ed11602158
No known key found for this signature in database
2 changed files with 36 additions and 0 deletions

View file

@ -0,0 +1,35 @@
using Iceshrimp.Frontend.Core.Miscellaneous;
using Iceshrimp.Shared.Schemas.Web;
namespace Iceshrimp.Frontend.Core.Services;
internal class SettingsService(ApiService api, ILogger<SettingsService> logger)
{
private UserSettingsResponse? UserSettings { get; set; }
public async Task<UserSettingsResponse> GetUserSettingsAsync()
{
if (UserSettings is null)
{
while (UserSettings is null)
{
await UpdateUserSettingsAsync();
}
}
_ = UpdateUserSettingsAsync();
return UserSettings;
}
private async Task UpdateUserSettingsAsync()
{
try
{
UserSettings = await api.Settings.GetSettingsAsync();
}
catch (ApiException e)
{
logger.LogError(e, "Failed to fetch settings");
}
}
}

View file

@ -30,6 +30,7 @@ builder.Services.AddSingleton<VersionService>();
builder.Services.AddSingleton<MessageService>();
builder.Services.AddSingleton<GlobalComponentSvc>();
builder.Services.AddSingleton<UpdateService>();
builder.Services.AddSingleton<SettingsService>();
builder.Services.AddAuthorizationCore();
builder.Services.AddCascadingAuthenticationState();
builder.Services.AddBlazoredLocalStorageAsSingleton();