forked from dotnet-presentations/blazor-workshop
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f6eb3a9
commit db10b1c
Showing
26 changed files
with
293 additions
and
236 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
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
src/BlazingPizza.Client/App.cshtml → src/BlazingPizza.Client/App.razor
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,3 +1,3 @@ | ||
<UserStateProvider> | ||
<Router AppAssembly=typeof(Program).Assembly /> | ||
</UserStateProvider> | ||
</UserStateProvider> |
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 was deleted.
Oops, something went wrong.
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,109 @@ | ||
@page "/myorders/{orderId:int}" | ||
@using System.Threading | ||
@layout ForceSignInLayout | ||
@inject IUriHelper UriHelper | ||
@inject HttpClient HttpClient | ||
@implements IDisposable | ||
|
||
<div class="main"> | ||
@if (invalidOrder) | ||
{ | ||
<h2>Nope</h2> | ||
<p>Sorry, this order could not be loaded.</p> | ||
} | ||
else if (orderWithStatus == null) | ||
{ | ||
<text>Loading...</text> | ||
} | ||
else | ||
{ | ||
<div class="track-order"> | ||
<div class="track-order-title"> | ||
<h2> | ||
Order placed @orderWithStatus.Order.CreatedTime.ToLongDateString() | ||
</h2> | ||
<p class="ml-auto mb-0"> | ||
Status: <strong>@orderWithStatus.StatusText</strong> | ||
</p> | ||
</div> | ||
<div class="track-order-body"> | ||
<div class="track-order-details"> | ||
@foreach (var pizza in orderWithStatus.Order.Pizzas) | ||
{ | ||
<p> | ||
<strong> | ||
@(pizza.Size)" | ||
@pizza.Special.Name | ||
(£@pizza.GetFormattedTotalPrice()) | ||
</strong> | ||
</p> | ||
|
||
<ul> | ||
@foreach (var topping in pizza.Toppings) | ||
{ | ||
<li>+ @topping.Topping.Name</li> | ||
} | ||
</ul> | ||
} | ||
|
||
<p> | ||
<strong> | ||
Total price: | ||
£@orderWithStatus.Order.GetFormattedTotalPrice() | ||
</strong> | ||
</p> | ||
</div> | ||
<div class="track-order-map"> | ||
<Map Zoom="13" Markers="@orderWithStatus.MapMarkers" /> | ||
</div> | ||
</div> | ||
</div> | ||
} | ||
</div> | ||
|
||
@functions { | ||
[Parameter] int OrderId { get; set; } | ||
|
||
OrderWithStatus orderWithStatus; | ||
bool invalidOrder; | ||
CancellationTokenSource pollingCancellationToken; | ||
|
||
string BaseUri => UriHelper.GetBaseUri().TrimEnd('/'); | ||
|
||
protected override void OnParametersSet() | ||
{ | ||
// If we were already polling for a different order, stop doing so | ||
pollingCancellationToken?.Cancel(); | ||
|
||
// Start a new poll loop | ||
PollForUpdates(); | ||
} | ||
|
||
void IDisposable.Dispose() | ||
{ | ||
pollingCancellationToken?.Cancel(); | ||
} | ||
|
||
private async void PollForUpdates() | ||
{ | ||
pollingCancellationToken = new CancellationTokenSource(); | ||
while (!pollingCancellationToken.IsCancellationRequested) | ||
{ | ||
try | ||
{ | ||
invalidOrder = false; | ||
orderWithStatus = await HttpClient.GetJsonAsync<OrderWithStatus>($"{BaseUri}/orders/{OrderId}"); | ||
} | ||
catch (Exception ex) | ||
{ | ||
invalidOrder = true; | ||
pollingCancellationToken.Cancel(); | ||
Console.Error.WriteLine(ex); | ||
} | ||
|
||
StateHasChanged(); | ||
|
||
await Task.Delay(4000); | ||
} | ||
} | ||
} |
File renamed without changes.
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
File renamed without changes.
2 changes: 1 addition & 1 deletion
2
...za.Client/Shared/ForceSignInLayout.cshtml → ...zza.Client/Shared/ForceSignInLayout.razor
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
2 changes: 1 addition & 1 deletion
2
...zingPizza.Client/Shared/MainLayout.cshtml → ...azingPizza.Client/Shared/MainLayout.razor
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
File renamed without changes.
Oops, something went wrong.