- @foreach (var item in items)
+ @foreach (var item in _items)
{
@Item(item)
@@ -20,17 +20,20 @@ else
}
-@code {
- IEnumerable
items;
-
+@code {
+ IEnumerable _items = null!;
+
[Parameter] public Func>> Loader { get; set; }
[Parameter] public RenderFragment Loading { get; set; }
- [Parameter] public RenderFragment Empty { get; set; }
+ [Parameter] public RenderFragment Empty { get; set; }
[Parameter] public RenderFragment Item { get; set; }
- [Parameter] public string ListGroupClass { get; set; }
+ [Parameter] public string? ListGroupClass { get; set; }
protected override async Task OnParametersSetAsync()
- {
- items = await Loader();
+ {
+ if (Loader is not null)
+ {
+ _items = await Loader();
+ }
}
}
diff --git a/src/BlazingPizza.Client/BlazingPizza.Client.csproj b/src/BlazingPizza.Client/BlazingPizza.Client.csproj
index b19daa6e..f57961dd 100644
--- a/src/BlazingPizza.Client/BlazingPizza.Client.csproj
+++ b/src/BlazingPizza.Client/BlazingPizza.Client.csproj
@@ -1,15 +1,16 @@
- net5.0
+ net6.0
+ true
-
-
+
+
diff --git a/src/BlazingPizza.Client/GlobalUsings.cs b/src/BlazingPizza.Client/GlobalUsings.cs
new file mode 100644
index 00000000..44fd643b
--- /dev/null
+++ b/src/BlazingPizza.Client/GlobalUsings.cs
@@ -0,0 +1,7 @@
+global using Microsoft.AspNetCore.Components.WebAssembly.Authentication;
+global using Microsoft.AspNetCore.Components.WebAssembly.Hosting;
+global using BlazingPizza.Client;
+global using System.Net.Http.Json;
+global using Microsoft.JSInterop;
+global using Microsoft.AspNetCore.Components;
+global using Microsoft.AspNetCore.SignalR.Client;
diff --git a/src/BlazingPizza.Client/JSRuntimeExtensions.cs b/src/BlazingPizza.Client/JSRuntimeExtensions.cs
index 89da520c..d55f09dd 100644
--- a/src/BlazingPizza.Client/JSRuntimeExtensions.cs
+++ b/src/BlazingPizza.Client/JSRuntimeExtensions.cs
@@ -1,13 +1,9 @@
-using Microsoft.JSInterop;
-using System.Threading.Tasks;
-
-namespace BlazingPizza.Client
-{
- public static class JSRuntimeExtensions
- {
- public static ValueTask Confirm(this IJSRuntime jsRuntime, string message)
- {
- return jsRuntime.InvokeAsync("confirm", message);
- }
- }
+namespace BlazingPizza.Client;
+
+public static class JSRuntimeExtensions
+{
+ public static ValueTask Confirm(this IJSRuntime jsRuntime, string message)
+ {
+ return jsRuntime.InvokeAsync("confirm", message);
+ }
}
diff --git a/src/BlazingPizza.Client/OrderState.cs b/src/BlazingPizza.Client/OrderState.cs
index 5265ae39..04b16c67 100644
--- a/src/BlazingPizza.Client/OrderState.cs
+++ b/src/BlazingPizza.Client/OrderState.cs
@@ -1,55 +1,46 @@
-using System.Collections.Generic;
-
-namespace BlazingPizza.Client
-{
- public class OrderState
- {
- public bool ShowingConfigureDialog { get; private set; }
-
- public Pizza ConfiguringPizza { get; private set; }
-
- public Order Order { get; private set; } = new Order();
-
- public void ShowConfigurePizzaDialog(PizzaSpecial special)
- {
- ConfiguringPizza = new Pizza()
- {
- Special = special,
- SpecialId = special.Id,
- Size = Pizza.DefaultSize,
- Toppings = new List(),
- };
-
- ShowingConfigureDialog = true;
- }
-
- public void CancelConfigurePizzaDialog()
- {
- ConfiguringPizza = null;
- ShowingConfigureDialog = false;
- }
-
- public void ConfirmConfigurePizzaDialog()
- {
- Order.Pizzas.Add(ConfiguringPizza);
- ConfiguringPizza = null;
-
- ShowingConfigureDialog = false;
- }
-
- public void RemoveConfiguredPizza(Pizza pizza)
- {
- Order.Pizzas.Remove(pizza);
- }
-
- public void ResetOrder()
- {
- Order = new Order();
- }
-
- public void ReplaceOrder(Order order)
- {
- Order = order;
- }
- }
+namespace BlazingPizza.Client;
+
+public class OrderState
+{
+ public bool ShowingConfigureDialog { get; private set; }
+
+ public Pizza ConfiguringPizza { get; private set; } = default!;
+
+ public Order Order { get; private set; } = new();
+
+ public void ShowConfigurePizzaDialog(PizzaSpecial special)
+ {
+ ConfiguringPizza = new Pizza()
+ {
+ Special = special,
+ SpecialId = special.Id,
+ Size = Pizza.DefaultSize,
+ Toppings = new List(),
+ };
+
+ ShowingConfigureDialog = true;
+ }
+
+ public void CancelConfigurePizzaDialog()
+ {
+ ConfiguringPizza = null;
+ ShowingConfigureDialog = false;
+ }
+
+ public void ConfirmConfigurePizzaDialog()
+ {
+ if (ConfiguringPizza is not null)
+ {
+ Order.Pizzas.Add(ConfiguringPizza);
+ ConfiguringPizza = null;
+ }
+
+ ShowingConfigureDialog = false;
+ }
+
+ public void RemoveConfiguredPizza(Pizza pizza) => Order.Pizzas.Remove(pizza);
+
+ public void ResetOrder() => Order = new Order();
+
+ public void ReplaceOrder(Order order) => Order = order;
}
diff --git a/src/BlazingPizza.Client/OrdersClient.cs b/src/BlazingPizza.Client/OrdersClient.cs
index 01c63572..ca7cde72 100644
--- a/src/BlazingPizza.Client/OrdersClient.cs
+++ b/src/BlazingPizza.Client/OrdersClient.cs
@@ -1,41 +1,29 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Net.Http;
-using System.Net.Http.Json;
-using System.Threading.Tasks;
-
-namespace BlazingPizza.Client
-{
- public class OrdersClient
- {
- private readonly HttpClient httpClient;
-
- public OrdersClient(HttpClient httpClient)
- {
- this.httpClient = httpClient;
- }
-
- public async Task> GetOrders() =>
- await httpClient.GetFromJsonAsync>("orders");
-
-
- public async Task GetOrder(int orderId) =>
- await httpClient.GetFromJsonAsync($"orders/{orderId}");
-
-
- public async Task PlaceOrder(Order order)
- {
- var response = await httpClient.PostAsJsonAsync("orders", order);
- response.EnsureSuccessStatusCode();
- var orderId = await response.Content.ReadFromJsonAsync();
- return orderId;
- }
-
- public async Task SubscribeToNotifications(NotificationSubscription subscription)
- {
- var response = await httpClient.PutAsJsonAsync("notifications/subscribe", subscription);
- response.EnsureSuccessStatusCode();
- }
- }
+namespace BlazingPizza.Client;
+
+public class OrdersClient
+{
+ private readonly HttpClient _httpClient;
+
+ public OrdersClient(HttpClient httpClient) => _httpClient = httpClient;
+
+ public async Task> GetOrders() =>
+ await _httpClient.GetFromJsonAsync>("orders");
+
+
+ public async Task GetOrder(int orderId) =>
+ await _httpClient.GetFromJsonAsync($"orders/{orderId}");
+
+ public async Task PlaceOrder(Order order)
+ {
+ var response = await _httpClient.PostAsJsonAsync("orders", order);
+ response.EnsureSuccessStatusCode();
+ var orderId = await response.Content.ReadFromJsonAsync();
+ return orderId;
+ }
+
+ public async Task SubscribeToNotifications(NotificationSubscription subscription)
+ {
+ var response = await _httpClient.PutAsJsonAsync("notifications/subscribe", subscription);
+ response.EnsureSuccessStatusCode();
+ }
}
diff --git a/src/BlazingPizza.Client/Pages/Authentication.razor b/src/BlazingPizza.Client/Pages/Authentication.razor
index abed0b1f..954940bd 100644
--- a/src/BlazingPizza.Client/Pages/Authentication.razor
+++ b/src/BlazingPizza.Client/Pages/Authentication.razor
@@ -11,7 +11,7 @@
@code{
[Parameter] public string Action { get; set; }
- public PizzaAuthenticationState RemoteAuthenticationState { get; set; } = new PizzaAuthenticationState();
+ public PizzaAuthenticationState RemoteAuthenticationState { get; set; } = new();
protected override void OnInitialized()
{
@@ -24,7 +24,7 @@
private void RestorePizza(PizzaAuthenticationState pizzaState)
{
- if (pizzaState.Order != null)
+ if (pizzaState.Order is not null)
{
OrderState.ReplaceOrder(pizzaState.Order);
}
diff --git a/src/BlazingPizza.Client/Pages/Checkout.razor b/src/BlazingPizza.Client/Pages/Checkout.razor
index 611f152c..0b82a161 100644
--- a/src/BlazingPizza.Client/Pages/Checkout.razor
+++ b/src/BlazingPizza.Client/Pages/Checkout.razor
@@ -19,7 +19,7 @@
-