refactor(app): add theme toggle functionality and improve theme management
This commit is contained in:
@@ -22,7 +22,7 @@
|
||||
<div class="dialog-content" @onclick:stopPropagation="true">
|
||||
<h5>Über Dümpelkas · 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
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user