feat: add theme mode support with AppThemeMode enum and AppThemeState service
- Introduced AppThemeMode enum to define theme options: System, Light, Dark. - Updated AppSettingsDocument to include ThemeMode property. - Created AppThemeState service to manage current theme mode and handle changes. - Integrated theme mode handling in CouchbaseLiteAppSettingsService for persistence. - Added JavaScript for theme management in the frontend, supporting system preference detection. - Enhanced CSS with theme variables for consistent styling across light and dark modes. - Updated Playwright tests to ensure sidebar functionality and responsiveness.
This commit is contained in:
parent
b45eac8055
commit
158906fa28
19 changed files with 889 additions and 82 deletions
41
Services/Settings/AppThemeState.cs
Normal file
41
Services/Settings/AppThemeState.cs
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
using WorkTracker.Domain;
|
||||
|
||||
namespace WorkTracker.Services.Settings;
|
||||
|
||||
public sealed class AppThemeState
|
||||
{
|
||||
private readonly IAppSettingsService appSettingsService;
|
||||
private AppThemeMode? currentThemeMode;
|
||||
|
||||
public AppThemeState(IAppSettingsService appSettingsService)
|
||||
{
|
||||
this.appSettingsService = appSettingsService;
|
||||
}
|
||||
|
||||
public event Action<AppThemeMode>? ThemeModeChanged;
|
||||
|
||||
public AppThemeMode CurrentThemeMode => currentThemeMode ?? AppThemeMode.System;
|
||||
|
||||
public async Task<AppThemeMode> EnsureLoadedAsync(CancellationToken cancellationToken = default)
|
||||
{
|
||||
if (currentThemeMode.HasValue)
|
||||
{
|
||||
return currentThemeMode.Value;
|
||||
}
|
||||
|
||||
var settings = await appSettingsService.GetAsync(cancellationToken);
|
||||
currentThemeMode = settings.ThemeMode;
|
||||
return CurrentThemeMode;
|
||||
}
|
||||
|
||||
public void SetThemeMode(AppThemeMode themeMode)
|
||||
{
|
||||
if (currentThemeMode == themeMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
currentThemeMode = themeMode;
|
||||
ThemeModeChanged?.Invoke(themeMode);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue