From 862b43ae6d0d01bf5dd397c048c7e7fbeacd28c0 Mon Sep 17 00:00:00 2001 From: Moritz Deiaco Date: Sun, 9 Jun 2024 10:33:04 +0200 Subject: [PATCH] Fixed some dump mistakes --- .../Core/Configuration/CoreConfiguration.cs | 4 ++-- .../Partials/CookieConsentBanner.razor | 21 ++++++++++++++----- Moonlight/Core/UI/Layouts/MainLayout.razor | 5 ++--- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Moonlight/Core/Configuration/CoreConfiguration.cs b/Moonlight/Core/Configuration/CoreConfiguration.cs index 3dc24700..c972e95e 100644 --- a/Moonlight/Core/Configuration/CoreConfiguration.cs +++ b/Moonlight/Core/Configuration/CoreConfiguration.cs @@ -151,9 +151,9 @@ public class CoreConfiguration public class CookieData { - [JsonProperty("ShowCookieConsentBanner")] + [JsonProperty("Enabled")] [Description("This specifies if the cookie consent banner is shown to users.")] - public bool ShowBanner { get; set; } = true; + public bool Enabled { get; set; } = true; [JsonProperty("BannerTitle")] [Description("The title for the cookie consent banner.")] diff --git a/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor b/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor index 8d79b088..f6b4b00e 100644 --- a/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor +++ b/Moonlight/Core/UI/Components/Partials/CookieConsentBanner.razor @@ -6,9 +6,7 @@ @inject ConfigService ConfigService @inject IdentityService IdentityService -@ChildContent - -@if (ConfigService.Get().Customisation.CookieConsentBanner.ShowBanner && !IdentityService.HasFlag("CookieAsked").Result) +@if (ShowBanner) {
@@ -31,10 +29,23 @@
} + @code { - [Parameter] - public RenderFragment ChildContent { get; set; } + private bool ShowBanner; + + protected override async Task OnAfterRenderAsync(bool firstRender) + { + if (firstRender) + { + var userWasAsked = await IdentityService.HasFlag("CookieAsked"); + + if (ConfigService.Get().Customisation.CookieConsentBanner.Enabled && !userWasAsked) + ShowBanner = true; + + await InvokeAsync(StateHasChanged); + } + } private async Task Consent() { diff --git a/Moonlight/Core/UI/Layouts/MainLayout.razor b/Moonlight/Core/UI/Layouts/MainLayout.razor index f5884ab6..f0007150 100644 --- a/Moonlight/Core/UI/Layouts/MainLayout.razor +++ b/Moonlight/Core/UI/Layouts/MainLayout.razor @@ -55,9 +55,8 @@ if (IdentityService.IsLoggedIn) { - - @Body - + @Body + } else