From 771b72696618bff28160de23efcc047118c11434 Mon Sep 17 00:00:00 2001 From: bakes82 Date: Thu, 24 Aug 2023 00:19:08 -0400 Subject: [PATCH 1/2] Add Loading Screen Component. --- src/Blazor.Server.UI/App.razor | 13 ++ .../Components/Shared/LoadingScreen.razor | 148 ++++++++++++++++++ 2 files changed, 161 insertions(+) create mode 100644 src/Blazor.Server.UI/Components/Shared/LoadingScreen.razor diff --git a/src/Blazor.Server.UI/App.razor b/src/Blazor.Server.UI/App.razor index ff8ad08e6..7ea044605 100644 --- a/src/Blazor.Server.UI/App.razor +++ b/src/Blazor.Server.UI/App.razor @@ -1,6 +1,8 @@ +@using Blazor.Server.UI.Services.Layout @inject IStringLocalizer L + @@ -31,3 +33,14 @@ + +@code{ + [Inject] private LayoutService LayoutService { get; set; } + + protected override async Task OnInitializedAsync() + { + await base.OnInitializedAsync(); + LayoutService.SetBaseTheme(Theme.Theme.ApplicationTheme()); + await LayoutService.ApplyUserPreferences(true); + } +} \ No newline at end of file diff --git a/src/Blazor.Server.UI/Components/Shared/LoadingScreen.razor b/src/Blazor.Server.UI/Components/Shared/LoadingScreen.razor new file mode 100644 index 000000000..ac0516624 --- /dev/null +++ b/src/Blazor.Server.UI/Components/Shared/LoadingScreen.razor @@ -0,0 +1,148 @@ +@using Blazor.Server.UI.Services.Layout +@inherits LayoutComponentBase + +@if (_isLoaded) +{ + @ChildContent +} +else +{ + var randomNumber = new Random().Next(-45, -15) + "%"; + var randomNumber2 = new Random().Next(10, 30) + "%"; +
+ + +
+
+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
+} + +@code { + + [Parameter] + public RenderFragment ChildContent { get; set; } + + [Parameter] + public LayoutService LayoutService { get; set; } + + [Parameter] + public int LoadingDelayMs { get; set; } + + private bool _isLoaded; + + private string Gradient => $"background-image: linear-gradient(-120deg, {(LayoutService.IsDarkMode ? LayoutService.CurrentTheme.PaletteDark.Background : LayoutService.CurrentTheme.Palette.Background)} 50%, {(LayoutService.IsDarkMode ? LayoutService.CurrentTheme.PaletteDark.Surface : LayoutService.CurrentTheme.Palette.Surface)} 50%);"; + + protected override async Task OnInitializedAsync() + { + await Task.Delay(LoadingDelayMs); + _isLoaded = true; + } +} \ No newline at end of file From 398df606b02ef7026fc01cc95625219528d58929 Mon Sep 17 00:00:00 2001 From: Bram1903 <70259613+Bram1903@users.noreply.github.com> Date: Thu, 24 Aug 2023 11:19:40 +0200 Subject: [PATCH 2/2] Add configurable loading screen duration A change was made to the App.razor, DashboardSettings.cs, and appsettings.json files to add a configurable loading screen duration setting in the application. Now, users can adjust the duration of the loading screen according to their preferences. This change makes the application more customizable and user-friendly. --- .../Common/Configurations/DashbordSettings.cs | 29 +++++--- src/Blazor.Server.UI/App.razor | 73 ++++++++++--------- src/Blazor.Server.UI/appsettings.json | 2 + 3 files changed, 60 insertions(+), 44 deletions(-) diff --git a/src/Application/Common/Configurations/DashbordSettings.cs b/src/Application/Common/Configurations/DashbordSettings.cs index 8471eeeb3..afb00513f 100644 --- a/src/Application/Common/Configurations/DashbordSettings.cs +++ b/src/Application/Common/Configurations/DashbordSettings.cs @@ -13,41 +13,50 @@ public class DashboardSettings /// public const string Key = nameof(DashboardSettings); + /// + /// Specifies whether to enable the loading screen + /// + public bool EnableLoadingScreen { get; set; } = true; + + /// + /// Specifies the duration of the loading screen in milliseconds + /// + public int LoadingScreenDuration { get; set; } = 3000; + /// /// Current application version /// public string Version { get; set; } = "1.3.0"; - + /// /// Application framework /// - + public string App { get; set; } = "Blazor"; - + /// /// The application name / title /// public string AppName { get; set; } = "Blazor Dashboard"; - + /// /// Application framework including the version /// - + public string AppFlavor { get; set; } = "Blazor .NET 7.0"; - + /// /// Application .NET version /// public string AppFlavorSubscript { get; set; } = ".NET 7"; - + /// /// The name of the company /// public string Company { get; set; } = "Company"; - + /// /// Copyright watermark /// public string Copyright { get; set; } = "@2023 Copyright"; - -} +} \ No newline at end of file diff --git a/src/Blazor.Server.UI/App.razor b/src/Blazor.Server.UI/App.razor index 7ea044605..5003f3432 100644 --- a/src/Blazor.Server.UI/App.razor +++ b/src/Blazor.Server.UI/App.razor @@ -1,46 +1,51 @@ @using Blazor.Server.UI.Services.Layout - @inject IStringLocalizer L - - - - - - - - @L["Please wait, we are authorizing you..."] - - - @if (@context.User.Identity?.IsAuthenticated??false) - { -

@L["You are not authorized to be here. For more information, contact your system administrator."]

- } - else - { - - } -
-
+ + + + + + + + @L["Please wait, we are authorizing you..."] + + + @if (context.User.Identity?.IsAuthenticated ?? false) + { +

@L["You are not authorized to be here. For more information, contact your system administrator."]

+ } + else + { + + } +
+
-
- - Not found - - -

@L["Sorry, there's nothing at this address."] @L["Go Home"]

-
-
-
-
-
+
+ + Not found + + +

+ @L["Sorry, there's nothing at this address."] @L["Go Home"] +

+
+
+
+
+
+ @code{ - [Inject] private LayoutService LayoutService { get; set; } - + + [Inject] + private LayoutService LayoutService { get; set; } + protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); LayoutService.SetBaseTheme(Theme.Theme.ApplicationTheme()); await LayoutService.ApplyUserPreferences(true); } + } \ No newline at end of file diff --git a/src/Blazor.Server.UI/appsettings.json b/src/Blazor.Server.UI/appsettings.json index e23c7503e..9aa421ed1 100644 --- a/src/Blazor.Server.UI/appsettings.json +++ b/src/Blazor.Server.UI/appsettings.json @@ -25,6 +25,8 @@ "Resilience": false }, "DashboardSettings": { + "EnableLoadingScreen": true, + "LoadingScreenDuration": 3000, "Version": "1.3.0", "App": "Blazor", "AppName": "Blazor Dashboard",