Commit c992ab9e authored by Steve Sanderson's avatar Steve Sanderson
Browse files

Move sign-in guard into a reusable layout. Some cleanups.

parent c7c81fe5
......@@ -85,7 +85,7 @@
waitDialogMessage = null;
}
async Task ShowConfigurePizzaDialog(PizzaSpecial special)
void ShowConfigurePizzaDialog(PizzaSpecial special)
{
pizza = new Pizza()
{
......
@page "/myorders"
@layout ForceSignInLayout
@inject HttpClient HttpClient
<div class="main px-4 py-4">
@if (!UserState.IsLoggedIn)
{
<h2>You're logged out</h2>
<text>Please log in to continue.</text>
}
else if (ordersWithStatus == null)
@if (ordersWithStatus == null)
{
<text>Loading...</text>
}
......@@ -48,13 +44,8 @@
@functions {
List<OrderWithStatus> ordersWithStatus;
[CascadingParameter] UserStateProvider UserState { get; set; }
protected override async Task OnParametersSetAsync()
{
if (UserState.IsLoggedIn)
{
ordersWithStatus = await HttpClient.GetJsonAsync<List<OrderWithStatus>>("/orders");
}
ordersWithStatus = await HttpClient.GetJsonAsync<List<OrderWithStatus>>("/orders");
}
}
@page "/myorders/{orderId:int}"
@layout ForceSignInLayout
@using System.Threading
@inject HttpClient HttpClient
@implements IDisposable
<div class="main px-4 py-4">
@if (!UserState.CurrentUser.IsLoggedIn)
{
<h2>You're logged out</h2>
<p>Please log in to continue.</p>
}
else if (invalidOrder)
@if (invalidOrder)
{
<h2>Nope</h2>
<p>Sorry, this order could not be loaded.</p>
......@@ -67,8 +63,6 @@
@functions {
[Parameter] int OrderId { get; set; }
[CascadingParameter] UserStateProvider UserState { get; set; }
OrderWithStatus orderWithStatus;
bool invalidOrder;
CancellationTokenSource pollingCancellationToken;
......@@ -78,11 +72,8 @@
// If we were already polling for a different order, stop doing so
pollingCancellationToken?.Cancel();
if (UserState.IsLoggedIn)
{
// Start a new poll loop
PollForUpdates();
}
// Start a new poll loop
PollForUpdates();
}
void IDisposable.Dispose()
......
@inherits BlazorLayoutComponent
@layout MainLayout
@if (UserState.CurrentUser == null) // Retrieving the login state
{
<text>Loading...</text>
}
else if (UserState.IsLoggedIn)
{
@Body
}
else
{
<div class="main px-4 py-4">
<h2>You're signed out</h2>
<p>To continue, please sign in.</p>
<button class="btn btn-danger" onclick="@UserState.SignIn">Sign in</button>
</div>
}
@functions {
[CascadingParameter] UserStateProvider UserState { get; set; }
}
......@@ -8,7 +8,7 @@
<img src="img/user.svg" />
<div>
<span class="username">@UserState.CurrentUser.DisplayName</span>
<a href="" onclick="@UserState.SignOut">Sign out</a>
<span class="sign-out" onclick="@UserState.SignOut">Sign out</span>
</div>
}
else
......
......@@ -461,3 +461,13 @@ button.sign-in {
color: #fff2cc;
border-color: #fff2cc;
}
.user-info .sign-out {
color: #fff2cc;
font-size: 0.8rem;
cursor: pointer;
}
.user-info .sign-out:hover {
text-decoration: underline;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment