From 65a3a086cc29886151af7bd895a16f885f4dd121 Mon Sep 17 00:00:00 2001 From: ysmoradi Date: Thu, 19 Dec 2024 22:54:19 +0100 Subject: [PATCH] Improve Boilerplate home page data loading (#9515) --- .../Components/Pages/HomePage.razor | 98 +++++++++---------- .../Components/Pages/HomePage.razor.cs | 18 ++-- 2 files changed, 60 insertions(+), 56 deletions(-) diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/HomePage.razor b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/HomePage.razor index b49e8792bf..df148a62f5 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/HomePage.razor +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/HomePage.razor @@ -23,71 +23,71 @@ Statistics - - @if (isLoadingGitHub) + + @if (isLoadingNuget) { - - - + + + } - else if (gitHubStats is not null) + else if (nugetStats is not null) { - - - Name: - @gitHubStats.Name - - - Total stars: - @gitHubStats.StargazersCount.ToString("N0") - - - Forks count: - @gitHubStats.ForksCount.ToString("N0") - - - Repo: - - - + var data = nugetStats.Data[0]; + + + Package id: + @data.Id + + + Version: + @data.Version + + + Total downloads: + @data.TotalDownloads.ToString("N0") + - } else { - GitHub stats could not be loaded. + Nuget stats could not be loaded. } - - @if (isLoadingNuget) + + @if (isLoadingGitHub) { - - - + + + } - else if (nugetStats is not null) + else if (gitHubStats is not null) { - var data = nugetStats.Data[0]; - - - Package id: - @data.Id - - - Version: - @data.Version - - - Total downloads: - @data.TotalDownloads.ToString("N0") + + + Name: + @gitHubStats.Name + + + Total stars: + @gitHubStats.StargazersCount.ToString("N0") + + + Forks count: + @gitHubStats.ForksCount.ToString("N0") + + + Repo: + + + + - } else { - Nuget stats could not be loaded. + GitHub stats could not be loaded. } diff --git a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/HomePage.razor.cs b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/HomePage.razor.cs index b2846c7c99..74752535ed 100644 --- a/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/HomePage.razor.cs +++ b/src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/Pages/HomePage.razor.cs @@ -30,31 +30,35 @@ protected override async Task OnInitAsync() // However, the logic in other HTTP message handlers, such as **LoggingDelegatingHandler** and **RetryDelegatingHandler**, // effectively addresses most scenarios. - await Task.WhenAll(LoadGitHub(), LoadNuget()); + await Task.WhenAll(LoadNuget(), LoadGitHub()); } - private async Task LoadGitHub() + private async Task LoadNuget() { try { - gitHubStats = await statisticsController.GetGitHubStats(CurrentCancellationToken); + nugetStats = await statisticsController.GetNugetStats(packageId: "Bit.BlazorUI", CurrentCancellationToken); } finally { - isLoadingGitHub = false; + isLoadingNuget = false; await InvokeAsync(StateHasChanged); } } - private async Task LoadNuget() + private async Task LoadGitHub() { try { - nugetStats = await statisticsController.GetNugetStats(packageId: "Bit.BlazorUI", CurrentCancellationToken); + if (InPrerenderSession is false) // GitHub results (2nd Bit Pivot tab) aren't shown by default and aren't critical for SEO, so skip pre-rendering to save time. + { + gitHubStats = await statisticsController.GetGitHubStats(CurrentCancellationToken); + } } + catch { /* `GetGitHubStats` calls the GitHub API directly from the client. We've intentionally skipped proper exception handling to keep this example simple. */ } finally { - isLoadingNuget = false; + isLoadingGitHub = false; await InvokeAsync(StateHasChanged); } }