-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
34 changed files
with
1,491 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
@page "/" | ||
|
||
<h1>Individual Spinners</h1> | ||
<div class="row"> | ||
<div class="col"> | ||
<p>Chase</p> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<Router AppAssembly="@typeof(Program).Assembly"> | ||
<Found Context="routeData"> | ||
<RouteView RouteData="@routeData" DefaultLayout="@typeof(MainLayout)" /> | ||
</Found> | ||
<NotFound> | ||
<LayoutView Layout="@typeof(MainLayout)"> | ||
<p>Sorry, there's nothing at this address.</p> | ||
</LayoutView> | ||
</NotFound> | ||
</Router> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
using System; | ||
|
||
namespace SsbSample.Data | ||
{ | ||
public class WeatherForecast | ||
{ | ||
public DateTime Date { get; set; } | ||
|
||
public int TemperatureC { get; set; } | ||
|
||
public int TemperatureF => 32 + (int)(TemperatureC / 0.5556); | ||
|
||
public string Summary { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace SsbSample.Data | ||
{ | ||
public class WeatherForecastService | ||
{ | ||
private static readonly string[] Summaries = new[] | ||
{ | ||
"Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching" | ||
}; | ||
|
||
public async Task<WeatherForecast[]> GetForecastAsync(DateTime startDate) | ||
{ | ||
await Task.Delay(3000); | ||
var rng = new Random(); | ||
return await Task.FromResult(Enumerable.Range(1, 5).Select(index => new WeatherForecast | ||
{ | ||
Date = startDate.AddDays(index), | ||
TemperatureC = rng.Next(-20, 55), | ||
Summary = Summaries[rng.Next(Summaries.Length)] | ||
}).ToArray()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
@page "/error" | ||
|
||
|
||
<h1 class="text-danger">Error.</h1> | ||
<h2 class="text-danger">An error occurred while processing your request.</h2> | ||
|
||
<h3>Development Mode</h3> | ||
<p> | ||
Swapping to <strong>Development</strong> environment will display more detailed information about the error that occurred. | ||
</p> | ||
<p> | ||
<strong>The Development environment shouldn't be enabled for deployed applications.</strong> | ||
It can result in displaying sensitive information from exceptions to end users. | ||
For local debugging, enable the <strong>Development</strong> environment by setting the <strong>ASPNETCORE_ENVIRONMENT</strong> environment variable to <strong>Development</strong> | ||
and restarting the app. | ||
</p> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
@page "/fetchdata" | ||
@using SsbSample.Data | ||
@inject WeatherForecastService WeatherService | ||
|
||
<h1>Weather forecast</h1> | ||
|
||
<p>This component demonstrates fetching data from the server.</p> | ||
<p> | ||
The <SpinLoader> component supports three template regions: | ||
<ul> | ||
<li>LoadingTemplate (optional) - content to display while the IsLoading property is <b>true</b>.</li> | ||
<li>ContentTemplate - content to display when the IsLoading is <b>false</b></li> | ||
<li>FaultedTemplate - content to display when IsFaulted is <b>true</b> and IsLoading is <b>false</b></li> | ||
</ul> | ||
</p> | ||
<div class="form-row align-items-center"> | ||
<div class="col-auto"> | ||
<div class="form-check mb-2"> | ||
<input id="forceException" type="checkbox" @bind="forceException" class="form-check-input" /> | ||
<label class="form-check-label" for="forceException">Force exception</label> | ||
</div> | ||
</div> | ||
<div class="col-auto"> | ||
<button class="btn btn-primary mb-2" @onclick="LoadData">Retry</button> | ||
</div> | ||
</div> | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Temp. (C)</th> | ||
<th>Temp. (F)</th> | ||
<th>Summary</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
<SpinLoader IsLoading="isLoading" IsFaulted="isFaulted"> | ||
<LoadingTemplate> | ||
<tr> | ||
<td colspan="4" style="vertical-align: middle;background-color: rgb(0, 0, 0, .2); height:300px;"> | ||
<Circle Color="#e67e22" Size="60px" Center="true" /> | ||
</td> | ||
</tr> | ||
</LoadingTemplate> | ||
<ContentTemplate> | ||
@foreach (var forecast in forecasts) | ||
{ | ||
<tr> | ||
<td>@forecast.Date.ToShortDateString()</td> | ||
<td>@forecast.TemperatureC</td> | ||
<td>@forecast.TemperatureF</td> | ||
<td>@forecast.Summary</td> | ||
</tr> | ||
} | ||
</ContentTemplate> | ||
<FaultedContentTemplate> | ||
<tr> | ||
<td colspan="4"> | ||
<div class="alert alert-danger">Fail</div> | ||
</td> | ||
</tr> | ||
</FaultedContentTemplate> | ||
</SpinLoader> | ||
</tbody> | ||
</table> | ||
|
||
@code { | ||
|
||
WeatherForecast[] forecasts; | ||
bool isFaulted = false; | ||
bool isLoading = true; | ||
int delay = 2000; | ||
bool forceException = false; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
await LoadData(); | ||
} | ||
|
||
async Task LoadData() | ||
{ | ||
await TryLoadingData( | ||
onSuccess: SuccessPath, | ||
onFaulted: FaultedPath | ||
); | ||
} | ||
|
||
void SuccessPath(WeatherForecast[] data) | ||
{ | ||
// do work | ||
forecasts = data; | ||
} | ||
|
||
void FaultedPath(Exception e) | ||
{ | ||
// log message, don't share it with the user | ||
var fakeLog = e.Message; | ||
} | ||
|
||
async Task TryLoadingData(Action<WeatherForecast[]> onSuccess, Action<Exception> onFaulted) | ||
{ | ||
isLoading = true; | ||
try | ||
{ | ||
if (forceException) | ||
{ | ||
throw new NotSupportedException(); | ||
} | ||
var data = await WeatherService.GetForecastAsync(DateTime.Now); | ||
isFaulted = false; | ||
onSuccess(data); | ||
} | ||
catch (Exception e) | ||
{ | ||
isFaulted = true; | ||
onFaulted(e); | ||
} | ||
finally | ||
{ | ||
isLoading = false; | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.