Skip to content

Commit

Permalink
Improve Boilerplate home page data loading (#9515)
Browse files Browse the repository at this point in the history
  • Loading branch information
ysmoradi committed Dec 19, 2024
1 parent f4382c4 commit 65a3a08
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,71 +23,71 @@
<BitStack>
<BitText Typography="BitTypography.H5">Statistics</BitText>
<BitPivot Style="width:100%" Styles="@(new() { Body = "overflow:auto" })">
<BitPivotItem HeaderText="GitHub">
@if (isLoadingGitHub)
<BitPivotItem HeaderText="Nuget">
@if (isLoadingNuget)
{
<BitStack HorizontalAlign="BitAlignment.Center">
<BitRippleLoading />
</BitStack>
<BitStack HorizontalAlign="BitAlignment.Center">
<BitRippleLoading />
</BitStack>
}
else if (gitHubStats is not null)
else if (nugetStats is not null)
{
<BitStack>
<BitStack Horizontal>
<BitText>Name:</BitText>
<BitText><b>@gitHubStats.Name</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Total stars:</BitText>
<BitText><b>@gitHubStats.StargazersCount.ToString("N0")</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Forks count:</BitText>
<BitText><b>@gitHubStats.ForksCount.ToString("N0")</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Repo:</BitText>
<BitLink Target="_blank"
Href="https://github.com/bitfoundation/bitplatform/tree/develop/src/Templates/Boilerplate">
<BitImage Alt="bitplatform GitHub stars"
Src="https://img.shields.io/github/stars/bitfoundation/bitplatform?style=social&label=Github%20%E2%9C%A8" />
</BitLink>
var data = nugetStats.Data[0];
<BitStack>
<BitStack Horizontal>
<BitText>Package id:</BitText>
<BitText><b>@data.Id</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Version:</BitText>
<BitText><b>@data.Version</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Total downloads:</BitText>
<BitText><b>@data.TotalDownloads.ToString("N0")</b></BitText>
</BitStack>
</BitStack>
</BitStack>
}
else
{
<BitText Typography="BitTypography.H4">GitHub stats could not be loaded.</BitText>
<BitText Typography="BitTypography.H4">Nuget stats could not be loaded.</BitText>
}
</BitPivotItem>
<BitPivotItem HeaderText="Nuget">
@if (isLoadingNuget)
<BitPivotItem HeaderText="GitHub">
@if (isLoadingGitHub)
{
<BitStack HorizontalAlign="BitAlignment.Center">
<BitRippleLoading />
</BitStack>
<BitStack HorizontalAlign="BitAlignment.Center">
<BitRippleLoading />
</BitStack>
}
else if (nugetStats is not null)
else if (gitHubStats is not null)
{
var data = nugetStats.Data[0];
<BitStack>
<BitStack Horizontal>
<BitText>Package id:</BitText>
<BitText><b>@data.Id</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Version:</BitText>
<BitText><b>@data.Version</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Total downloads:</BitText>
<BitText><b>@data.TotalDownloads.ToString("N0")</b></BitText>
<BitStack>
<BitStack Horizontal>
<BitText>Name:</BitText>
<BitText><b>@gitHubStats.Name</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Total stars:</BitText>
<BitText><b>@gitHubStats.StargazersCount.ToString("N0")</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Forks count:</BitText>
<BitText><b>@gitHubStats.ForksCount.ToString("N0")</b></BitText>
</BitStack>
<BitStack Horizontal>
<BitText>Repo:</BitText>
<BitLink Target="_blank"
Href="https://github.com/bitfoundation/bitplatform/tree/develop/src/Templates/Boilerplate">
<BitImage Alt="bitplatform GitHub stars"
Src="https://img.shields.io/github/stars/bitfoundation/bitplatform?style=social&label=Github%20%E2%9C%A8" />
</BitLink>
</BitStack>
</BitStack>
</BitStack>
}
else
{
<BitText Typography="BitTypography.H4">Nuget stats could not be loaded.</BitText>
<BitText Typography="BitTypography.H4">GitHub stats could not be loaded.</BitText>
}
</BitPivotItem>
</BitPivot>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down

0 comments on commit 65a3a08

Please sign in to comment.