Skip to content

Commit 744fb8d

Browse files
authored
Merge pull request #362 from neozhu/fluxor
Consider reusing fluxor + rename property name
2 parents 88fffde + df9b394 commit 744fb8d

32 files changed

+476
-296
lines changed

src/Application/Application.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.1" />
1818
<PackageReference Include="FluentValidation" Version="11.5.2" />
1919
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.5.2" />
20+
<PackageReference Include="Fluxor.Blazor.Web" Version="5.7.0" />
21+
<PackageReference Include="Fluxor.Blazor.Web.ReduxDevTools" Version="5.7.0" />
2022
<PackageReference Include="LazyCache" Version="2.4.0" />
2123
<PackageReference Include="LazyCache.AspNetCore" Version="2.4.0" />
2224
<PackageReference Include="Microsoft.AspNetCore.Components.Web" Version="7.0.5" />

src/Application/DependencyInjection.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
2929
config.AddOpenBehavior(typeof(CacheInvalidationBehaviour<,>));
3030

3131

32+
});
33+
services.AddFluxor(options => {
34+
options.ScanAssemblies(Assembly.GetExecutingAssembly());
35+
options.UseReduxDevTools();
3236
});
3337
services.AddLazyCache();
3438
services.AddScoped<PicklistService>();
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using CleanArchitecture.Blazor.Application.Common.Interfaces.Identity;
2+
3+
namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
4+
public class Effects
5+
{
6+
7+
private readonly IIdentityService _identityService;
8+
9+
public Effects(IIdentityService identityService)
10+
{
11+
12+
_identityService = identityService;
13+
}
14+
[EffectMethod]
15+
public async Task HandleFetchDataAction(FetchUserDtoAction action, IDispatcher dispatcher)
16+
{
17+
var result = await _identityService.GetApplicationUserDto(action.UserId);
18+
if(result is not null)
19+
dispatcher.Dispatch(new FetchUserDtoResultAction(result));
20+
}
21+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
2+
public class FetchUserDtoAction
3+
{
4+
public required string UserId { get; set; }
5+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
using CleanArchitecture.Blazor.Application.Features.Identity.Dto;
2+
3+
namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
4+
public class FetchUserDtoResultAction
5+
{
6+
public UserProfile UserProfile { get; }
7+
public FetchUserDtoResultAction(ApplicationUserDto dto)
8+
{
9+
UserProfile = new UserProfile()
10+
{
11+
UserId = dto.Id,
12+
ProfilePictureDataUrl = dto.ProfilePictureDataUrl,
13+
Email = dto.Email,
14+
PhoneNumber = dto.PhoneNumber,
15+
DisplayName = dto.DisplayName,
16+
Provider = dto.Provider,
17+
UserName = dto.UserName,
18+
TenantId = dto.TenantId,
19+
TenantName = dto.TenantName,
20+
SuperiorId = dto.SuperiorId,
21+
SuperiorName = dto.SuperiorName,
22+
AssignedRoles = dto.AssignedRoles,
23+
DefaultRole = dto.DefaultRole
24+
};
25+
}
26+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
2+
public static class Reducers
3+
{
4+
[ReducerMethod]
5+
public static UserProfileState ReduceUserProfileUpdateAction(UserProfileState state, UserProfileUpdateAction action) => new(false,action.UserProfile);
6+
[ReducerMethod]
7+
public static UserProfileState ReduceFetchUserDtoAction(UserProfileState state, FetchUserDtoAction action) => new(true, null);
8+
[ReducerMethod]
9+
public static UserProfileState ReduceFetchUserDtoResultAction(UserProfileState state, FetchUserDtoResultAction action) => new(false,action.UserProfile);
10+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
using CleanArchitecture.Blazor.Application.Features.Identity.Dto;
2+
3+
namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
4+
[FeatureState]
5+
public class UserProfileState
6+
{
7+
public UserProfile UserProfile { get; }
8+
public bool IsLoading { get; }
9+
public UserProfileState()
10+
{
11+
IsLoading = true;
12+
UserProfile = new() { Email= "", UserId="",UserName= "" };
13+
}
14+
public UserProfileState(bool loading,UserProfile? userProfile)
15+
{
16+
IsLoading = loading;
17+
UserProfile = userProfile?? new() { Email = "", UserId = "", UserName = "" }; ;
18+
}
19+
public UserProfileState(ApplicationUserDto dto)
20+
{
21+
UserProfile = new UserProfile()
22+
{
23+
UserId = dto.Id,
24+
ProfilePictureDataUrl = dto.ProfilePictureDataUrl,
25+
Email = dto.Email,
26+
PhoneNumber = dto.PhoneNumber,
27+
DisplayName = dto.DisplayName,
28+
Provider = dto.Provider,
29+
UserName = dto.UserName,
30+
IsActive = dto.IsActive,
31+
TenantId = dto.TenantId,
32+
TenantName = dto.TenantName,
33+
SuperiorId = dto.SuperiorId,
34+
SuperiorName = dto.SuperiorName,
35+
AssignedRoles = dto.AssignedRoles,
36+
DefaultRole = dto.DefaultRole
37+
};
38+
}
39+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
2+
public class UserProfileUpdateAction
3+
{
4+
public required UserProfile UserProfile { get; set; }
5+
}

src/Application/_Imports.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
global using MediatR;
2+
global using Fluxor;
23
global using MediatR.Pipeline;
34
global using LazyCache;
45
global using Microsoft.Extensions.Localization;

src/Blazor.Server.UI/App.razor

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

22
@inject IStringLocalizer<SharedResource> L
3-
3+
<Fluxor.Blazor.Web.StoreInitializer />
44
<CascadingAuthenticationState>
55
<Router AppAssembly="@typeof(App).Assembly">
66
<Found Context="routeData">

0 commit comments

Comments
 (0)