@inherits LayoutComponentBase @inject IJSRuntime JSRuntime @using Blazored.Toast
LiteCharms Affordable Technology Today
+27872650198 @* Refactored: Mailto link with subject and body *@ contact@litecharms.co.za
@Body
@* Cookie Banner Added Here *@ @if (showBanner) { }
@code { private bool isMenuOpen = false; private bool showBanner = false; private bool isInitialized = false; private void ToggleMenu() { isMenuOpen = !isMenuOpen; } private void CloseMenu() { isMenuOpen = false; } protected override async Task OnAfterRenderAsync(bool firstRender) { // Only run this logic once when the component first renders if (firstRender && !isInitialized) { isInitialized = true; try { // Attempt to read from localStorage var consent = await JSRuntime.InvokeAsync("localStorage.getItem", "litecharms_cookie_consent"); // If no consent is found, show the banner if (string.IsNullOrWhiteSpace(consent)) { await Task.Delay(500); // Wait for page to settle showBanner = true; StateHasChanged(); } } catch (Exception ex) { // If JS Interop fails (e.g., storage blocked), default to showing the banner Console.WriteLine($"Cookie check failed: {ex.Message}"); showBanner = true; StateHasChanged(); } } } private async Task HandleConsent(bool accepted) { showBanner = false; try { // Save preference await JSRuntime.InvokeVoidAsync("localStorage.setItem", "litecharms_cookie_consent", accepted ? "accepted" : "rejected"); } catch { // Fail silently if storage is unavailable } StateHasChanged(); } }