-
Notifications
You must be signed in to change notification settings - Fork 57
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #264 from TimeWarpEngineering/Cramer/2021-08-15/Cl…
…eanup Add Tutorial Sample and some cleanup
- Loading branch information
Showing
76 changed files
with
2,357 additions
and
902 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
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" PreferExactMatches="@true"> | ||
<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,23 @@ | ||
namespace Sample.Client | ||
{ | ||
using System.Threading.Tasks; | ||
using BlazorState.Pipeline.ReduxDevTools; | ||
using BlazorState.Features.JavaScriptInterop; | ||
using BlazorState.Features.Routing; | ||
using Microsoft.AspNetCore.Components; | ||
|
||
public partial class App : ComponentBase | ||
{ | ||
[Inject] private JsonRequestHandler JsonRequestHandler { get; set; } | ||
[Inject] private ReduxDevToolsInterop ReduxDevToolsInterop { get; set; } | ||
|
||
// Injected so it is created by the container. Even though the IDE says it is not used, it is. | ||
[Inject] private RouteManager RouteManager { get; set; } | ||
|
||
protected override async Task OnAfterRenderAsync(bool firstRender) | ||
{ | ||
await ReduxDevToolsInterop.InitAsync(); | ||
await JsonRequestHandler.InitAsync(); | ||
} | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...es/Tutorial/Sample/Client/Features/Counter/Actions/IncrementCount/IncrementCountAction.cs
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,12 @@ | ||
namespace Sample.Client.Features.Counter | ||
{ | ||
using BlazorState; | ||
|
||
public partial class CounterState | ||
{ | ||
public class IncrementCountAction : IAction | ||
{ | ||
public int Amount { get; set; } | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
...s/Tutorial/Sample/Client/Features/Counter/Actions/IncrementCount/IncrementCountHandler.cs
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,23 @@ | ||
namespace Sample.Client.Features.Counter | ||
{ | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
using BlazorState; | ||
using MediatR; | ||
|
||
public partial class CounterState | ||
{ | ||
public class IncrementCountHandler : ActionHandler<IncrementCountAction> | ||
{ | ||
public IncrementCountHandler(IStore aStore) : base(aStore) { } | ||
|
||
CounterState CounterState => Store.GetState<CounterState>(); | ||
|
||
public override Task<Unit> Handle(IncrementCountAction aIncrementCountAction, CancellationToken aCancellationToken) | ||
{ | ||
CounterState.Count = CounterState.Count + aIncrementCountAction.Amount; | ||
return Unit.Task; | ||
} | ||
} | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
Samples/Tutorial/Sample/Client/Features/Counter/CounterState.cs
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 @@ | ||
namespace Sample.Client.Features.Counter | ||
{ | ||
using BlazorState; | ||
|
||
public partial class CounterState : State<CounterState> | ||
{ | ||
public int Count { get; private set; } | ||
public override void Initialize() => Count = 3; | ||
} | ||
} |
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,22 @@ | ||
@page "/counter" | ||
@using BlazorState | ||
@using Sample.Client.Features.Counter | ||
|
||
@inherits BlazorStateComponent | ||
|
||
<h1>Counter</h1> | ||
|
||
<p>Current count: @currentCount</p> | ||
|
||
<button class="btn btn-primary" @onclick="IncrementCount">Click me</button> | ||
|
||
@code { | ||
CounterState CounterState => GetState<CounterState>(); | ||
|
||
private int currentCount => CounterState.Count; | ||
|
||
async Task IncrementCount() | ||
{ | ||
await Mediator.Send(new CounterState.IncrementCountAction { Amount = 5 }); | ||
} | ||
} |
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,46 @@ | ||
@page "/fetchdata" | ||
@using Sample.Shared | ||
@inject HttpClient Http | ||
|
||
<h1>Weather forecast</h1> | ||
|
||
<p>This component demonstrates fetching data from the server.</p> | ||
|
||
@if (forecasts == null) | ||
{ | ||
<p><em>Loading...</em></p> | ||
} | ||
else | ||
{ | ||
<table class="table"> | ||
<thead> | ||
<tr> | ||
<th>Date</th> | ||
<th>Temp. (C)</th> | ||
<th>Temp. (F)</th> | ||
<th>Summary</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@foreach (var forecast in forecasts) | ||
{ | ||
<tr> | ||
<td>@forecast.Date.ToShortDateString()</td> | ||
<td>@forecast.TemperatureC</td> | ||
<td>@forecast.TemperatureF</td> | ||
<td>@forecast.Summary</td> | ||
</tr> | ||
} | ||
</tbody> | ||
</table> | ||
} | ||
|
||
@code { | ||
private WeatherForecast[] forecasts; | ||
|
||
protected override async Task OnInitializedAsync() | ||
{ | ||
forecasts = await Http.GetFromJsonAsync<WeatherForecast[]>("WeatherForecast"); | ||
} | ||
|
||
} |
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,7 @@ | ||
@page "/" | ||
|
||
<h1>Hello, world!</h1> | ||
|
||
Welcome to your new app. | ||
|
||
<SurveyPrompt Title="How is Blazor working for you?" /> |
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,41 @@ | ||
namespace Sample.Client | ||
{ | ||
using System; | ||
using System.Net.Http; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Components.WebAssembly.Hosting; | ||
using Microsoft.Extensions.DependencyInjection; | ||
using BlazorState; | ||
using System.Reflection; | ||
|
||
public class Program | ||
{ | ||
public static async Task Main(string[] args) | ||
{ | ||
var builder = WebAssemblyHostBuilder.CreateDefault(args); | ||
builder.RootComponents.Add<App>("#app"); | ||
|
||
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) }); | ||
|
||
ConfigureServices(builder.Services); | ||
|
||
await builder.Build().RunAsync(); | ||
} | ||
|
||
public static void ConfigureServices(IServiceCollection aServiceCollection) | ||
{ | ||
aServiceCollection.AddBlazorState | ||
( | ||
(aOptions) => | ||
{ | ||
aOptions.UseReduxDevToolsBehavior = true; | ||
aOptions.Assemblies = | ||
new Assembly[] | ||
{ | ||
typeof(Program).GetTypeInfo().Assembly, | ||
}; | ||
} | ||
); | ||
} | ||
} | ||
} |
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,18 @@ | ||
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly"> | ||
|
||
<PropertyGroup> | ||
<TargetFramework>net5.0</TargetFramework> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Blazor-State" Version="4.0.0" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="5.0.11" /> | ||
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="5.0.11" PrivateAssets="all" /> | ||
<PackageReference Include="System.Net.Http.Json" Version="5.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Shared\Sample.Shared.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,17 @@ | ||
@inherits LayoutComponentBase | ||
|
||
<div class="page"> | ||
<div class="sidebar"> | ||
<NavMenu /> | ||
</div> | ||
|
||
<div class="main"> | ||
<div class="top-row px-4"> | ||
<a href="http://blazor.net" target="_blank" class="ml-md-auto">About</a> | ||
</div> | ||
|
||
<div class="content px-4"> | ||
@Body | ||
</div> | ||
</div> | ||
</div> |
Oops, something went wrong.