refactor(app): add theme toggle functionality and improve theme management

This commit is contained in:
2026-04-03 14:51:45 +02:00
parent 68c7a1ca6a
commit e21a2fc1c5
5 changed files with 169 additions and 4 deletions

View File

@@ -22,7 +22,7 @@
<div class="dialog-content" @onclick:stopPropagation="true">
<h5>Über Dümpelkas &middot; Version @AppVersion</h5>
<p class="mb-2">Entwickler: Andre Beging</p>
<p class="mb-3">E-Mail: <a href="mailto:mail@beging.de" style="color: white;">mail@beging.de</a></p>
<p class="mb-3">E-Mail: <a href="mailto:mail@beging.de" style="color: var(--color-text);">mail@beging.de</a></p>
<div class="d-flex justify-content-end">
<button type="button" class="btn btn-outline-secondary" @onclick="CloseAboutDialog">
<i class="bi bi-x-lg"></i> Schließen

View File

@@ -39,6 +39,9 @@
<button class="btn btn-nav btn-primary" @onclick="OpenYearFilterDialog">
<i class="bi bi-funnel"></i> Ansicht<br>@GetFilterLabel()
</button>
<button class="btn btn-nav btn-secondary" @onclick="ToggleThemeAsync" title="Farbmodus wechseln">
<i class="@ThemeButtonIconClass"></i> Modus<br>@ThemeButtonLabel
</button>
</div>
@if (accounts != null && accounts.Any())

View File

@@ -1,5 +1,7 @@
using System.Globalization;
using Duempelkas.App.Services.Models;
using Microsoft.AspNetCore.Components;
using Microsoft.JSInterop;
namespace Duempelkas.App.Pages;
@@ -18,6 +20,7 @@ public partial class Dashboard
private string? operationMessage;
private string operationMessageClass = "alert-info";
private string? savedPdfPath;
private string currentTheme = "light";
#endregion
@@ -37,6 +40,26 @@ public partial class Dashboard
await LoadAll();
}
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
{
return;
}
try
{
currentTheme = await JS.InvokeAsync<string>("duempelkasThemeGetCurrentTheme");
}
catch (JSException)
{
// Keep default light mode when JS interop is not ready or unavailable.
currentTheme = "light";
}
StateHasChanged();
}
#endregion
#region Data Loading
@@ -167,5 +190,24 @@ public partial class Dashboard
private string GetFilterLabel() => selectedYear?.ToString() ?? "Alle";
private string ThemeButtonLabel => currentTheme == "dark" ? "Hell" : "Dunkel";
private string ThemeButtonIconClass => currentTheme == "dark" ? "bi bi-sun" : "bi bi-moon-stars";
private async Task ToggleThemeAsync()
{
try
{
currentTheme = await JS.InvokeAsync<string>("duempelkasThemeToggleTheme");
}
catch (JSException)
{
currentTheme = currentTheme == "dark" ? "light" : "dark";
}
}
[Inject]
private IJSRuntime JS { get; set; } = default!;
#endregion
}