Skip to content

Commit 348bb5f

Browse files
committed
Added Blazor Loading Component
1 parent b99d683 commit 348bb5f

40 files changed

+3126
-2
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazorLoadingComponent", "BlazorLoadingComponent\BlazorLoadingComponent.csproj", "{17E674E3-CFDF-4F9B-A9CD-11A77E7439C9}"
4+
EndProject
5+
Global
6+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
7+
Debug|Any CPU = Debug|Any CPU
8+
Release|Any CPU = Release|Any CPU
9+
EndGlobalSection
10+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
11+
{17E674E3-CFDF-4F9B-A9CD-11A77E7439C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
12+
{17E674E3-CFDF-4F9B-A9CD-11A77E7439C9}.Debug|Any CPU.Build.0 = Debug|Any CPU
13+
{17E674E3-CFDF-4F9B-A9CD-11A77E7439C9}.Release|Any CPU.ActiveCfg = Release|Any CPU
14+
{17E674E3-CFDF-4F9B-A9CD-11A77E7439C9}.Release|Any CPU.Build.0 = Release|Any CPU
15+
EndGlobalSection
16+
EndGlobal
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
2+
<s:Boolean x:Key="/Default/CodeInspection/CodeAnnotations/NamespacesWithAnnotations/=BlazorLoadingComponent_002EAnnotations/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<Router AppAssembly="@typeof(App).Assembly">
2+
<Found Context="routeData">
3+
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)"/>
4+
<FocusOnNavigate RouteData="@routeData" Selector="h1"/>
5+
</Found>
6+
<NotFound>
7+
<PageTitle>Not found</PageTitle>
8+
<LayoutView Layout="@typeof(MainLayout)">
9+
<p role="alert">Sorry, there's nothing at this address.</p>
10+
</LayoutView>
11+
</NotFound>
12+
</Router>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<Project Sdk="Microsoft.NET.Sdk.Web">
2+
3+
<PropertyGroup>
4+
<TargetFramework>net6.0</TargetFramework>
5+
<Nullable>enable</Nullable>
6+
<ImplicitUsings>enable</ImplicitUsings>
7+
</PropertyGroup>
8+
9+
</Project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
namespace BlazorLoadingComponent.Data;
2+
3+
public class WeatherForecast
4+
{
5+
public DateTime Date { get; set; }
6+
7+
public int TemperatureC { get; set; }
8+
9+
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
10+
11+
public string? Summary { get; set; }
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
namespace BlazorLoadingComponent.Data;
2+
3+
public class WeatherForecastService
4+
{
5+
private static readonly string[] Summaries = new[]
6+
{
7+
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
8+
};
9+
10+
public Task<WeatherForecast[]> GetForecastAsync(DateTime startDate)
11+
{
12+
return Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast
13+
{
14+
Date = startDate.AddDays(index),
15+
TemperatureC = Random.Shared.Next(-20, 55),
16+
Summary = Summaries[Random.Shared.Next(Summaries.Length)]
17+
}).ToArray());
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
@page "/counter"
2+
3+
<PageTitle>Counter</PageTitle>
4+
5+
<h1>Counter</h1>
6+
7+
<p role="status">Current count: @currentCount</p>
8+
9+
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>
10+
11+
@code {
12+
private int currentCount = 0;
13+
14+
private void IncrementCount()
15+
{
16+
currentCount++;
17+
}
18+
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@page
2+
@model BlazorLoadingComponent.Pages.ErrorModel
3+
4+
<!DOCTYPE html>
5+
<html lang="en">
6+
7+
<head>
8+
<meta charset="utf-8"/>
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
10+
<title>Error</title>
11+
<link href="~/css/bootstrap/bootstrap.min.css" rel="stylesheet"/>
12+
<link href="~/css/site.css" rel="stylesheet" asp-append-version="true"/>
13+
</head>
14+
15+
<body>
16+
<div class="main">
17+
<div class="content px-4">
18+
<h1 class="text-danger">Error.</h1>
19+
<h2 class="text-danger">An error occurred while processing your request.</h2>
20+
21+
@if (Model.ShowRequestId)
22+
{
23+
<p>
24+
<strong>Request ID:</strong> <code>@Model.RequestId</code>
25+
</p>
26+
}
27+
28+
<h3>Development Mode</h3>
29+
<p>
30+
Swapping to the <strong>Development</strong> environment displays detailed information about the error that occurred.
31+
</p>
32+
<p>
33+
<strong>The Development environment shouldn't be enabled for deployed applications.</strong>
34+
It can result in displaying sensitive information from exceptions to end users.
35+
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong>
36+
and restarting the app.
37+
</p>
38+
</div>
39+
</div>
40+
</body>
41+
42+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using System.Diagnostics;
2+
using Microsoft.AspNetCore.Mvc;
3+
using Microsoft.AspNetCore.Mvc.RazorPages;
4+
5+
namespace BlazorLoadingComponent.Pages;
6+
7+
[ResponseCache(Duration = 0, Location = ResponseCacheLocation.None, NoStore = true)]
8+
[IgnoreAntiforgeryToken]
9+
public class ErrorModel : PageModel
10+
{
11+
public string? RequestId { get; set; }
12+
13+
public bool ShowRequestId => !string.IsNullOrEmpty(RequestId);
14+
15+
private readonly ILogger<ErrorModel> _logger;
16+
17+
public ErrorModel(ILogger<ErrorModel> logger)
18+
{
19+
_logger = logger;
20+
}
21+
22+
public void OnGet()
23+
{
24+
RequestId = Activity.Current?.Id ?? HttpContext.TraceIdentifier;
25+
}
26+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
@page "/fetchdata"
2+
3+
<PageTitle>Weather forecast</PageTitle>
4+
5+
@using BlazorLoadingComponent.Data
6+
@inject WeatherForecastService ForecastService
7+
8+
<h1>Weather forecast</h1>
9+
10+
<p>This component demonstrates fetching data from a service.</p>
11+
12+
@if (forecasts == null)
13+
{
14+
<p>
15+
<em>Loading...</em>
16+
</p>
17+
}
18+
else
19+
{
20+
<table class="table">
21+
<thead>
22+
<tr>
23+
<th>Date</th>
24+
<th>Temp. (C)</th>
25+
<th>Temp. (F)</th>
26+
<th>Summary</th>
27+
</tr>
28+
</thead>
29+
<tbody>
30+
@foreach (var forecast in forecasts)
31+
{
32+
<tr>
33+
<td>@forecast.Date.ToShortDateString()</td>
34+
<td>@forecast.TemperatureC</td>
35+
<td>@forecast.TemperatureF</td>
36+
<td>@forecast.Summary</td>
37+
</tr>
38+
}
39+
</tbody>
40+
</table>
41+
}
42+
43+
@code {
44+
private WeatherForecast[]? forecasts;
45+
46+
protected override async Task OnInitializedAsync()
47+
{
48+
forecasts = await ForecastService.GetForecastAsync(DateTime.Now);
49+
}
50+
51+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
@page "/"
2+
3+
<PageTitle>Index</PageTitle>
4+
5+
<Loading>
6+
<ChildComponent>
7+
<HeavyWorkComponent></HeavyWorkComponent>
8+
</ChildComponent>
9+
</Loading>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
@page "/"
2+
@namespace BlazorLoadingComponent.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
@{
5+
Layout = "_Layout";
6+
}
7+
8+
<component type="typeof(App)" render-mode="ServerPrerendered"/>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
@using Microsoft.AspNetCore.Components.Web
2+
@namespace BlazorLoadingComponent.Pages
3+
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
4+
5+
<!DOCTYPE html>
6+
<html lang="en">
7+
<head>
8+
<meta charset="utf-8"/>
9+
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
10+
<base href="~/"/>
11+
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css"/>
12+
<link href="css/site.css" rel="stylesheet"/>
13+
<link href="BlazorLoadingComponent.styles.css" rel="stylesheet"/>
14+
<component type="typeof(HeadOutlet)" render-mode="ServerPrerendered"/>
15+
</head>
16+
<body>
17+
@RenderBody()
18+
19+
<div id="blazor-error-ui">
20+
<environment include="Staging,Production">
21+
An error has occurred. This application may no longer respond until reloaded.
22+
</environment>
23+
<environment include="Development">
24+
An unhandled exception has occurred. See browser dev tools for details.
25+
</environment>
26+
<a href="" class="reload">Reload</a>
27+
<a class="dismiss">🗙</a>
28+
</div>
29+
30+
<script src="_framework/blazor.server.js"></script>
31+
</body>
32+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
using Microsoft.AspNetCore.Components;
2+
using Microsoft.AspNetCore.Components.Web;
3+
using BlazorLoadingComponent.Data;
4+
5+
var builder = WebApplication.CreateBuilder(args);
6+
7+
// Add services to the container.
8+
builder.Services.AddRazorPages();
9+
builder.Services.AddServerSideBlazor();
10+
builder.Services.AddSingleton<WeatherForecastService>();
11+
12+
var app = builder.Build();
13+
14+
// Configure the HTTP request pipeline.
15+
if (!app.Environment.IsDevelopment())
16+
{
17+
app.UseExceptionHandler("/Error");
18+
// The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
19+
app.UseHsts();
20+
}
21+
22+
app.UseHttpsRedirection();
23+
24+
app.UseStaticFiles();
25+
26+
app.UseRouting();
27+
28+
app.MapBlazorHub();
29+
app.MapFallbackToPage("/_Host");
30+
31+
app.Run();

0 commit comments

Comments
 (0)