96 lines
2.6 KiB
Plaintext
96 lines
2.6 KiB
Plaintext
@page "/myorders/{orderId:int}"
|
|
@attribute [Authorize]
|
|
@using System.Threading
|
|
@inject OrdersClient OrdersClient
|
|
@implements IDisposable
|
|
|
|
<div class="main">
|
|
@if (invalidOrder)
|
|
{
|
|
<h2>NEIN</h2>
|
|
<p>Konnte keine Bestellungen laden</p>
|
|
}
|
|
else if (orderWithStatus == null)
|
|
{
|
|
<text>Lade...</text>
|
|
}
|
|
else
|
|
{
|
|
<div class="track-order">
|
|
<div class="track-order-title">
|
|
<h2>
|
|
Bestellt am @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">
|
|
<OrderReview Order="orderWithStatus.Order" />
|
|
</div>
|
|
<div class="track-order-map">
|
|
<Map Zoom="13" Markers="orderWithStatus.MapMarkers" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
|
|
@code {
|
|
[Parameter] public int OrderId { get; set; }
|
|
|
|
OrderWithStatus orderWithStatus;
|
|
bool invalidOrder;
|
|
CancellationTokenSource pollingCancellationToken;
|
|
|
|
protected override void OnParametersSet()
|
|
{
|
|
// If we were already polling for a different order, stop doing so
|
|
pollingCancellationToken?.Cancel();
|
|
|
|
// Start a new poll loop
|
|
PollForUpdates();
|
|
}
|
|
|
|
private async void PollForUpdates()
|
|
{
|
|
invalidOrder = false;
|
|
pollingCancellationToken = new CancellationTokenSource();
|
|
while (!pollingCancellationToken.IsCancellationRequested)
|
|
{
|
|
try
|
|
{
|
|
orderWithStatus = await OrdersClient.GetOrder(OrderId);
|
|
StateHasChanged();
|
|
|
|
if (orderWithStatus.IsDelivered)
|
|
{
|
|
pollingCancellationToken.Cancel();
|
|
}
|
|
else
|
|
{
|
|
await Task.Delay(4000);
|
|
}
|
|
}
|
|
catch (AccessTokenNotAvailableException ex)
|
|
{
|
|
pollingCancellationToken.Cancel();
|
|
ex.Redirect();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
invalidOrder = true;
|
|
pollingCancellationToken.Cancel();
|
|
Console.Error.WriteLine(ex);
|
|
StateHasChanged();
|
|
}
|
|
}
|
|
}
|
|
|
|
void IDisposable.Dispose()
|
|
{
|
|
pollingCancellationToken?.Cancel();
|
|
}
|
|
}
|