Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updates to loading screen, check dashboard settings #484

Merged
merged 2 commits into from
Aug 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 83 additions & 34 deletions src/Blazor.Server.UI/App.razor
Original file line number Diff line number Diff line change
@@ -1,51 +1,100 @@
@using Blazor.Server.UI.Services.Layout
@inject IStringLocalizer<SharedResource> L
@inject NavigationManager NavManager

<Fluxor.Blazor.Web.StoreInitializer/>
<LoadingScreen LayoutService="LayoutService" LoadingDelayMs="@(Settings.EnableLoadingScreen ? Settings.LoadingScreenDuration : 0)">
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<Authorizing>
<text>@L["Please wait, we are authorizing you..."]</text>
</Authorizing>
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated ?? false)
{
<p>@L["You are not authorized to be here. For more information, contact your system administrator."]</p>
}
else
{
<Login/>
}
</NotAuthorized>
</AuthorizeRouteView>

</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="d-flex">
<p role="alert">
@L["Sorry, there's nothing at this address."] <MudButton Variant="Variant.Filled" Size="Size.Small" Link="/">@L["Go Home"]</MudButton>
</p>
</MudContainer>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>

<LoadingScreen IsLoaded="@_isLoaded" LayoutService="LayoutService">
<div class="page-transition @_transitionClass">
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
<AuthorizeRouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)">
<Authorizing>
<text>@L["Please wait, we are authorizing you..."]</text>
</Authorizing>
<NotAuthorized>
@if (context.User.Identity?.IsAuthenticated ?? false)
{
<p>@L["You are not authorized to be here. For more information, contact your system administrator."]</p>
}
else
{
<Login/>
}
</NotAuthorized>
</AuthorizeRouteView>

</Found>
<NotFound>
<PageTitle>Not found</PageTitle>
<LayoutView Layout="@typeof(MainLayout)">
<MudContainer MaxWidth="MaxWidth.ExtraLarge" Class="d-flex">
<p role="alert">
@L["Sorry, there's nothing at this address."] <MudButton Variant="Variant.Filled" Size="Size.Small" Link="/">@L["Go Home"]</MudButton>
</p>
</MudContainer>
</LayoutView>
</NotFound>
</Router>
</CascadingAuthenticationState>
</div>
</LoadingScreen>

@code{

[Inject]
private LayoutService LayoutService { get; set; }

private string _transitionClass = "loadScreen-initial-hidden";
private bool _isLoaded = true;

protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
LayoutService.SetBaseTheme(Theme.Theme.ApplicationTheme());
await LayoutService.ApplyUserPreferences(true);
NavManager.LocationChanged += HandleLocationChanged;
}

protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
if (Settings.EnableLoadingScreen)
{
_transitionClass = "";
_isLoaded = false;
StateHasChanged();

await Task.Delay(Settings.LoadingScreenDuration >= 0 ? Settings.LoadingScreenDuration : 2000);

//transitionClass = "loadScreen-fade-in";
_isLoaded = true;
StateHasChanged();
}
}
}

private async void HandleLocationChanged(object sender, LocationChangedEventArgs e)
{
if (!Settings.EnableLoadingScreen) return;

//transitionClass = "loadScreen-fade-out";
_transitionClass = "";

_isLoaded = false;
StateHasChanged();

await Task.Delay(600);

//transitionClass = "loadScreen-fade-in";
_isLoaded = true;
StateHasChanged();
}

public void Dispose()
{
NavManager.LocationChanged -= HandleLocationChanged;
}

}
13 changes: 3 additions & 10 deletions src/Blazor.Server.UI/Components/Shared/LoadingScreen.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using Blazor.Server.UI.Services.Layout
@inherits LayoutComponentBase

@if (_isLoaded)
@if (IsLoaded)
{
@ChildContent
}
Expand Down Expand Up @@ -132,17 +132,10 @@ else

[Parameter]
public LayoutService LayoutService { get; set; }

[Parameter]
public int LoadingDelayMs { get; set; }

private bool _isLoaded;
[Parameter]
public bool IsLoaded { get; set; }

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;
}
}
15 changes: 14 additions & 1 deletion src/Blazor.Server.UI/wwwroot/css/app.css
Original file line number Diff line number Diff line change
@@ -1 +1,14 @@

.loadScreen-fade-in {
opacity: 1;
transition: opacity 0.5s ease-in-out;
}

.loadScreen-fade-out {
opacity: 0;
transition: opacity 0.5s ease-in-out;
}

.loadScreen-initial-hidden {
opacity: 0;
visibility: hidden;
}