Skip to content

Commit 4ffb21f

Browse files
committed
feat: Enhance UserProfile page with real API integration and improved UI
- Updated UserProfile.razor to utilize ReqResApi for fetching user data from JSONPlaceholder. - Improved loading states and error handling for user profile loading. - Expanded user selection options from 6 to 12 users. - Added a Quick Load section for faster user switching. - Refined UI elements for better user experience and clarity. - Introduced ReqResApi service for real API calls and data fetching. - Updated AsyncDataDemoState to remove simulated API calls and reflect real data fetching. - Created MiddlewareDemoState to demonstrate custom middleware functionality. - Implemented RealApiDemoState to showcase multiple public REST APIs. - Enhanced Query and QueryComponent classes for better query management and initialization.
1 parent 6d6331b commit 4ffb21f

19 files changed

Lines changed: 1661 additions & 375 deletions

samples/EasyAppDev.Blazor.Store.Sample/EasyAppDev.Blazor.Store.Sample.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk.BlazorWebAssembly">
22

33
<PropertyGroup>
4-
<TargetFramework>net10.0</TargetFramework>
4+
<TargetFramework>net9.0</TargetFramework>
55
<Nullable>enable</Nullable>
66
<ImplicitUsings>enable</ImplicitUsings>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="10.0.0-preview.1.25120.3" />
11-
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="10.0.0-preview.1.25120.3" PrivateAssets="all" />
10+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly" Version="9.0.0" />
11+
<PackageReference Include="Microsoft.AspNetCore.Components.WebAssembly.DevServer" Version="9.0.0" PrivateAssets="all" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

samples/EasyAppDev.Blazor.Store.Sample/Layout/NavMenu.razor

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,11 @@
104104
<span aria-hidden="true">:</span> Redux-Style Actions
105105
</NavLink>
106106
</div>
107+
<div class="nav-item px-3">
108+
<NavLink class="nav-link" href="middleware-demo">
109+
<span aria-hidden="true">|</span> Middleware System
110+
</NavLink>
111+
</div>
107112
<div class="nav-item px-3">
108113
<NavLink class="nav-link" href="plugin-demo">
109114
<span aria-hidden="true">[</span> Plugin System
@@ -129,6 +134,11 @@
129134
<span aria-hidden="true">,</span> Cross-Store Updates
130135
</NavLink>
131136
</div>
137+
<div class="nav-item px-3">
138+
<NavLink class="nav-link" href="real-api-demo">
139+
<span aria-hidden="true">@("@")</span> Real API Demo
140+
</NavLink>
141+
</div>
132142
<div class="nav-item px-3">
133143
<NavLink class="nav-link" href="comprehensive-demo">
134144
<span aria-hidden="true">/</span> All Features Demo
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
using System.Diagnostics;
2+
using EasyAppDev.Blazor.Store.Middleware;
3+
using EasyAppDev.Blazor.Store.Sample.State;
4+
5+
namespace EasyAppDev.Blazor.Store.Sample.Middleware;
6+
7+
/// <summary>
8+
/// Simple logging middleware that logs state changes to the console.
9+
/// Demonstrates basic middleware implementation.
10+
/// </summary>
11+
public class ConsoleLoggingMiddleware : IMiddleware<MiddlewareDemoState>
12+
{
13+
public Task OnBeforeUpdateAsync(MiddlewareDemoState currentState, string? action)
14+
{
15+
Console.WriteLine($"[BEFORE] Action: {action}, Current Counter: {currentState.Counter}");
16+
return Task.CompletedTask;
17+
}
18+
19+
public Task OnAfterUpdateAsync(MiddlewareDemoState previousState, MiddlewareDemoState newState, string? action)
20+
{
21+
Console.WriteLine($"[AFTER] Action: {action}, Counter: {previousState.Counter} -> {newState.Counter}");
22+
return Task.CompletedTask;
23+
}
24+
}
25+
26+
/// <summary>
27+
/// Performance tracking middleware that measures update duration.
28+
/// Demonstrates stateful middleware with Stopwatch.
29+
/// </summary>
30+
public class PerformanceMiddleware : IMiddleware<MiddlewareDemoState>
31+
{
32+
private readonly Stopwatch _stopwatch = new();
33+
34+
public Action<string?, TimeSpan>? OnActionCompleted { get; set; }
35+
36+
public Task OnBeforeUpdateAsync(MiddlewareDemoState currentState, string? action)
37+
{
38+
_stopwatch.Restart();
39+
return Task.CompletedTask;
40+
}
41+
42+
public Task OnAfterUpdateAsync(MiddlewareDemoState previousState, MiddlewareDemoState newState, string? action)
43+
{
44+
_stopwatch.Stop();
45+
OnActionCompleted?.Invoke(action, _stopwatch.Elapsed);
46+
return Task.CompletedTask;
47+
}
48+
}
49+
50+
/// <summary>
51+
/// Validation middleware that prevents invalid state changes.
52+
/// Demonstrates middleware that can affect state updates.
53+
/// </summary>
54+
public class ValidationMiddleware : IMiddleware<MiddlewareDemoState>
55+
{
56+
public int MinValue { get; set; } = -100;
57+
public int MaxValue { get; set; } = 100;
58+
59+
public Action<string>? OnValidationFailed { get; set; }
60+
61+
public Task OnBeforeUpdateAsync(MiddlewareDemoState currentState, string? action)
62+
{
63+
return Task.CompletedTask;
64+
}
65+
66+
public Task OnAfterUpdateAsync(MiddlewareDemoState previousState, MiddlewareDemoState newState, string? action)
67+
{
68+
if (newState.Counter < MinValue || newState.Counter > MaxValue)
69+
{
70+
OnValidationFailed?.Invoke($"Counter {newState.Counter} is out of range [{MinValue}, {MaxValue}]");
71+
}
72+
return Task.CompletedTask;
73+
}
74+
}
75+
76+
/// <summary>
77+
/// Action history middleware that tracks all actions.
78+
/// Demonstrates middleware that can update state with additional info.
79+
/// </summary>
80+
public class ActionHistoryMiddleware : IMiddleware<MiddlewareDemoState>
81+
{
82+
public List<(DateTime Time, string? Action, int PrevValue, int NewValue)> History { get; } = new();
83+
84+
public Task OnBeforeUpdateAsync(MiddlewareDemoState currentState, string? action)
85+
{
86+
return Task.CompletedTask;
87+
}
88+
89+
public Task OnAfterUpdateAsync(MiddlewareDemoState previousState, MiddlewareDemoState newState, string? action)
90+
{
91+
History.Add((DateTime.Now, action, previousState.Counter, newState.Counter));
92+
93+
// Keep only last 50 entries
94+
while (History.Count > 50)
95+
{
96+
History.RemoveAt(0);
97+
}
98+
99+
return Task.CompletedTask;
100+
}
101+
}

0 commit comments

Comments
 (0)