Skip to content

Commit 570d56c

Browse files
committed
Update 04-refactor-state-management
1 parent 32d0883 commit 570d56c

24 files changed

+207
-117
lines changed

docs/04-refactor-state-management.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ At this point it should be possible to get the `Index` component compiling again
108108
```csharp
109109
async Task PlaceOrder()
110110
{
111-
var newOrderId = await HttpClient.PostJsonAsync<int>("orders", OrderState.Order);
111+
var response = await HttpClient.PostAsJsonAsync("orders", OrderState.Order);
112+
var newOrderId = await response.Content.ReadFromJsonAsync<int>();
112113
OrderState.ResetOrder();
113114
NavigationManager.NavigateTo($"myorders/{newOrderId}");
114115
}

save-points/04-refactor-state-management/BlazingPizza.Client/App.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
</Found>
55
<NotFound>
66
<LayoutView Layout="typeof(MainLayout)">
7-
<div class="main">Page not found</div>
7+
<div class="main">Sorry, there's nothing at this address.</div>
88
</LayoutView>
99
</NotFound>
1010
</Router>

save-points/04-refactor-state-management/BlazingPizza.Client/BlazingPizza.Client.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<ItemGroup>
1010
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="$(BlazorVersion)" />
1111
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Build" Version="$(BlazorVersion)" PrivateAssets="all" />
12-
<PackageReference Include="Microsoft.AspNetCore.Blazor.HttpClient" Version="$(BlazorVersion)" />
13-
<PackageReference Include="Microsoft.AspNetCore.Components.Authorization" Version="$(AspNetCoreVersion)" />
12+
<PackageReference Include="System.Net.Http.Json" Version="$(SystemNetHttpJsonVersion)" />
13+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.Authentication" Version="$(BlazorVersion)" />
1414
</ItemGroup>
1515

1616
<ItemGroup>

save-points/04-refactor-state-management/BlazingPizza.Client/Pages/Index.razor

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,13 @@
6161

6262
protected override async Task OnInitializedAsync()
6363
{
64-
specials = await HttpClient.GetJsonAsync<List<PizzaSpecial>>("specials");
64+
specials = await HttpClient.GetFromJsonAsync<List<PizzaSpecial>>("specials");
6565
}
6666

6767
async Task PlaceOrder()
6868
{
69-
var newOrderId = await HttpClient.PostJsonAsync<int>("orders", Order);
69+
var response = await HttpClient.PostAsJsonAsync("orders", OrderState.Order);
70+
var newOrderId = await response.Content.ReadFromJsonAsync<int>();
7071
OrderState.ResetOrder();
7172
NavigationManager.NavigateTo($"myorders/{newOrderId}");
7273
}

save-points/04-refactor-state-management/BlazingPizza.Client/Pages/MyOrders.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,6 @@
4343

4444
protected override async Task OnParametersSetAsync()
4545
{
46-
ordersWithStatus = await HttpClient.GetJsonAsync<List<OrderWithStatus>>("orders");
46+
ordersWithStatus = await HttpClient.GetFromJsonAsync<List<OrderWithStatus>>("orders");
4747
}
4848
}

save-points/04-refactor-state-management/BlazingPizza.Client/Pages/OrderDetails.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
try
5858
{
5959
invalidOrder = false;
60-
orderWithStatus = await HttpClient.GetJsonAsync<OrderWithStatus>($"orders/{OrderId}");
60+
orderWithStatus = await HttpClient.GetFromJsonAsync<OrderWithStatus>($"orders/{OrderId}");
6161
}
6262
catch (Exception ex)
6363
{

save-points/04-refactor-state-management/BlazingPizza.Client/Shared/ConfigurePizzaDialog.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969

7070
protected async override Task OnInitializedAsync()
7171
{
72-
toppings = await HttpClient.GetJsonAsync<List<Topping>>("toppings");
72+
toppings = await HttpClient.GetFromJsonAsync<List<Topping>>("toppings");
7373
}
7474

7575
void ToppingSelected(ChangeEventArgs e)

save-points/04-refactor-state-management/BlazingPizza.Client/Shared/MainLayout.razor

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
@inherits LayoutComponentBase
22

33
<div class="top-bar">
4-
<img class="logo" src="img/logo.svg" />
4+
<a class="logo" href="">
5+
<img src="img/logo.svg" />
6+
</a>
57

68
<NavLink href="" class="nav-tab" Match="NavLinkMatch.All">
79
<img src="img/pizza-slice.svg" />

save-points/04-refactor-state-management/BlazingPizza.Client/_Imports.razor

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
@using System.Net.Http
2+
@using System.Net.Http.Headers
3+
@using System.Net.Http.Json
24
@using Microsoft.AspNetCore.Authorization
35
@using Microsoft.AspNetCore.Components.Authorization
46
@using Microsoft.AspNetCore.Components.Forms
57
@using Microsoft.AspNetCore.Components.Routing
68
@using Microsoft.AspNetCore.Components.Web
9+
@using Microsoft.AspNetCore.Components.WebAssembly.Authentication
710
@using Microsoft.JSInterop
811
@using BlazingPizza.Client
912
@using BlazingPizza.Client.Shared

save-points/04-refactor-state-management/BlazingPizza.Client/wwwroot/css/site.css

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ form {
3636
}
3737

3838
.logo {
39-
margin-right: 3rem;
40-
width: 9rem;
39+
display: flex;
4140
}
4241

42+
.logo > img {
43+
margin-right: 3rem;
44+
width: 9rem;
45+
}
46+
4347
.content {
4448
display: flex;
4549
height: 100%;
@@ -120,13 +124,21 @@ form {
120124
font-weight: 700;
121125
line-height: 0.7rem;
122126
margin-top: 0.5rem;
127+
color: white;
128+
font-size: 1rem;
123129
}
124130

125131
.user-info a {
126132
color: #fff2cc;
127133
font-size: 0.8rem;
128134
}
129135

136+
.user-info button.sign-out {
137+
color: #fff2cc;
138+
font-size: 0.8rem;
139+
padding: 0;
140+
}
141+
130142
.pizza-cards {
131143
display: grid;
132144
grid-template-columns: repeat(auto-fill, 20rem);
@@ -540,6 +552,7 @@ a.sign-in {
540552
font-weight: 100;
541553
cursor: pointer;
542554
transition: 0.2s ease-out;
555+
margin-left: 3px;
543556
}
544557

545558
a.sign-in:hover {
@@ -548,16 +561,6 @@ a.sign-in {
548561
border-color: #fff2cc;
549562
}
550563

551-
.user-info a.sign-out {
552-
color: #fff2cc;
553-
font-size: 0.8rem;
554-
cursor: pointer;
555-
}
556-
557-
.user-info a.sign-out:hover {
558-
text-decoration: underline;
559-
}
560-
561564
input[type=range] {
562565
-webkit-appearance: none;
563566
margin: 7.1px 0;
@@ -721,6 +724,25 @@ input[type=range] {
721724
color: red;
722725
}
723726

727+
#blazor-error-ui {
728+
background: lightyellow;
729+
bottom: 0;
730+
box-shadow: 0 -1px 2px rgba(0, 0, 0, 0.2);
731+
display: none;
732+
left: 0;
733+
padding: 0.6rem 1.25rem 0.7rem 1.25rem;
734+
position: fixed;
735+
width: 100%;
736+
z-index: 1000;
737+
}
738+
739+
#blazor-error-ui .dismiss {
740+
cursor: pointer;
741+
position: absolute;
742+
right: 0.75rem;
743+
top: 0.5rem;
744+
}
745+
724746
@keyframes progressbar-slide {
725747
0% {
726748
transform: translateX(-200px);
@@ -733,4 +755,4 @@ input[type=range] {
733755
100% {
734756
transform: translateX(500px);
735757
}
736-
}
758+
}

0 commit comments

Comments
 (0)