AuthorBuddy/Services/ThemeService.cs

25 lines
637 B
C#
Raw Normal View History

2026-05-16 16:13:35 +02:00
using Microsoft.JSInterop;
namespace AuthorBuddy.Web.Services;
public class ThemeService : IThemeService
{
private readonly IJSRuntime _js;
public ThemeService(IJSRuntime js)
{
_js = js;
}
public async Task ApplyTheme(string theme)
{
await _js.InvokeVoidAsync("eval",
$"document.getElementById('theme-css')?.remove(); " +
$"var link = document.createElement('link'); " +
$"link.id = 'theme-css'; " +
$"link.rel = 'stylesheet'; " +
$"link.href = 'css/themes/{theme}.css'; " +
$"document.head.appendChild(link);");
}
}