Files
CartriX/CartriX.Web/App.razor
T

46 lines
1.3 KiB
Plaintext

@using Microsoft.AspNetCore.Http
@using Microsoft.Extensions.Options
<RadzenTheme Theme="software" />
<script src="_content/Radzen.Blazor/Radzen.Blazor.js?v=@(typeof(Radzen.Colors).Assembly.GetName().Version)"></script>
<Router AppAssembly="@typeof(App).Assembly" NotFoundPage="@typeof(Pages.NotFound)">
<Found Context="routeData">
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" />
<FocusOnNavigate RouteData="@routeData" Selector="h1" />
</Found>
</Router>
@code {
[CascadingParameter]
private HttpContext HttpContext { get; set; } = default!;
[Inject]
private ThemeService ThemeService { get; set; } = default!;
[Inject]
private IOptions<CookieThemeServiceOptions> Options { get; set; } = default!;
protected override void OnInitialized()
{
base.OnInitialized();
if (HttpContext != null)
{
var theme = HttpContext.Request.Cookies["CartriXTheme"];
if (!string.IsNullOrEmpty(theme))
{
ThemeService.SetTheme(theme, false);
}
else
{
HttpContext.Response.Cookies.Append("CartriXTheme", "material", new CookieOptions { Secure = Options.Value.IsSecure, Expires = DateTimeOffset.Now.Add(Options.Value.Duration) });
}
}
}
}