Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace blazor-state with Fluxor #284

Merged
merged 3 commits into from
Feb 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Application/Application.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
<PackageReference Include="AutoFilterer" Version="2.13.0" />
<PackageReference Include="AutoMapper" Version="12.0.1" />
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="12.0.0" />
<PackageReference Include="Blazor-State" Version="7.0.0" />
<PackageReference Include="FluentValidation" Version="11.4.0" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.4.0" />
<PackageReference Include="Fluxor.Blazor.Web" Version="5.7.0" />
<PackageReference Include="Fluxor.Blazor.Web.ReduxDevTools" Version="5.7.0" />
<PackageReference Include="LazyCache" Version="2.4.0" />
<PackageReference Include="LazyCache.AspNetCore" Version="2.4.0" />
<PackageReference Include="MediatR.Extensions.Microsoft.DependencyInjection" Version="11.0.0" />
Expand All @@ -27,4 +28,7 @@
<ItemGroup>
<ProjectReference Include="..\Domain\Domain.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Features\Identity\Profile\" />
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/Application/Common/Models/UserProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class UserProfile
public string? PhoneNumber { get; set; }
public string? Role { get; set; }
public string[]? AssignRoles { get; set; }
public string UserId { get; set; }=Guid.NewGuid().ToString();
public required string UserId { get; set; }=Guid.NewGuid().ToString();
public bool IsActive { get; set; }
public string? TenantId { get; set; }
public string? TenantName { get; set; }
Expand Down
8 changes: 4 additions & 4 deletions src/Application/DependencyInjection.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using BlazorState;
using CleanArchitecture.Blazor.Application.Common.Behaviours;
using CleanArchitecture.Blazor.Application.Common.Interfaces.MultiTenant;
using CleanArchitecture.Blazor.Application.Common.Security;
Expand All @@ -19,9 +18,10 @@ public static IServiceCollection AddApplicationServices(this IServiceCollection
services.AddAutoMapper(Assembly.GetExecutingAssembly());
services.AddValidatorsFromAssembly(Assembly.GetExecutingAssembly());
services.AddMediatR(Assembly.GetExecutingAssembly());
services.AddBlazorState((options) => options.Assemblies = new Assembly[] {
Assembly.GetExecutingAssembly(),
});
services.AddFluxor(options => {
options.ScanAssemblies(Assembly.GetExecutingAssembly());
options.UseReduxDevTools();
});
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(UnhandledExceptionBehaviour<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(AuthorizationBehaviour<,>));
services.AddTransient(typeof(IPipelineBehavior<,>), typeof(ValidationBehaviour<,>));
Expand Down
12 changes: 12 additions & 0 deletions src/Application/Features/Fluxor/Reducers.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
public static class Reducers
{
[ReducerMethod]
public static UserProfileState ReduceUserProfileUpdateAction(UserProfileState state, UserProfileUpdateAction action) => new(action.UserProfile);
}
41 changes: 41 additions & 0 deletions src/Application/Features/Fluxor/UserProfileState.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CleanArchitecture.Blazor.Application.Features.Identity.Dto;

namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
[FeatureState]
public class UserProfileState
{
public UserProfile UserProfile { get; }
public UserProfileState()
{
UserProfile = new() { Email= "[email protected]", UserId=Guid.NewGuid().ToString(),UserName= "anonym" };
}
public UserProfileState(UserProfile userProfile)
{
UserProfile = userProfile;
}
public UserProfileState(UserDto dto)
{
UserProfile = new UserProfile()
{
UserId = dto.Id,
ProfilePictureDataUrl = dto.ProfilePictureDataUrl,
Email = dto.Email,
PhoneNumber = dto.PhoneNumber,
DisplayName = dto.DisplayName,
Provider = dto.Provider,
UserName = dto.UserName,
IsActive = dto.IsActive,
TenantId = dto.TenantId,
TenantName = dto.TenantName,
SuperiorId = dto.SuperiorId,
SuperiorName = dto.SuperiorName,
AssignRoles = dto.AssignRoles,
Role = dto.Role
};
}
}
11 changes: 11 additions & 0 deletions src/Application/Features/Fluxor/UserProfileUpdateAction.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CleanArchitecture.Blazor.Application.Features.Fluxor;
public class UserProfileUpdateAction
{
public required UserProfile UserProfile { get; set; }
}
20 changes: 20 additions & 0 deletions src/Application/Features/Identity/Dto/UserDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,24 @@ public class UserDto
public bool Checked { get; set; }
public string? Role { get; set; }
public DateTimeOffset? LockoutEnd { get; set; }

public UserProfile ToUserProfile => new()
{

UserId = Id,
ProfilePictureDataUrl = ProfilePictureDataUrl,
Email = Email,
PhoneNumber = PhoneNumber,
DisplayName = DisplayName,
Provider = Provider,
UserName = UserName,
IsActive = IsActive,
TenantId = TenantId,
TenantName = TenantName,
SuperiorId = SuperiorId,
SuperiorName = SuperiorName,
AssignRoles = AssignRoles,
Role = Role

};
}

This file was deleted.

This file was deleted.

31 changes: 0 additions & 31 deletions src/Application/Features/Identity/Profile/UserProfileState.cs

This file was deleted.

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions src/Application/Features/ThemeProfiles/ThemeProfilesState.cs

This file was deleted.

1 change: 1 addition & 0 deletions src/Application/_Imports.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
global using MediatR;
global using Fluxor;
global using MediatR.Pipeline;
global using LazyCache;
global using Microsoft.Extensions.Localization;
Expand Down
2 changes: 2 additions & 0 deletions src/Blazor.Server.UI/App.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@

@inject IStringLocalizer<SharedResource> L

<Fluxor.Blazor.Web.StoreInitializer />
<CascadingAuthenticationState>
<Router AppAssembly="@typeof(App).Assembly">
<Found Context="routeData">
Expand Down
4 changes: 2 additions & 2 deletions src/Blazor.Server.UI/Components/Shared/SideMenu.razor
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@using Blazor.Server.UI.Models.SideMenu
@using BlazorState

@inject IStringLocalizer<SideMenu> L
@inherits BlazorStateComponent
@inherits FluxorComponent
<MudDrawer Breakpoint="Breakpoint.Md"
Class="side-menu"
Elevation="0"
Expand Down
21 changes: 6 additions & 15 deletions src/Blazor.Server.UI/Components/Shared/SideMenu.razor.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
using Microsoft.AspNetCore.Components;
using MudBlazor;
using Blazor.Server.UI.Models.SideMenu;
using Blazor.Server.UI.Services;
using Blazor.Server.UI.Services.Navigation;
using CleanArchitecture.Blazor.Application.Common.Models;
using Microsoft.AspNetCore.Components.Authorization;
using CleanArchitecture.Blazor.Infrastructure.Extensions;
using BlazorState;
using CleanArchitecture.Blazor.Application.Features.Identity.Profile;


namespace Blazor.Server.UI.Components.Shared;

public partial class SideMenu:BlazorStateComponent,IDisposable
public partial class SideMenu
{
UserProfileState UserProfileState => GetState<UserProfileState>();
private UserProfile UserProfile => UserProfileState.UserProfile;
[Inject]
private IState<UserProfileState> UserProfileState { get; set; } = null!;
private UserProfile UserProfile => UserProfileState.Value.UserProfile;

[EditorRequired] [Parameter]
public bool SideMenuDrawerOpen { get; set; }
Expand All @@ -31,9 +26,5 @@ [EditorRequired] [Parameter]

private string[] _roles => UserProfile.AssignRoles??new string[] { };







}
3 changes: 1 addition & 2 deletions src/Blazor.Server.UI/Components/Shared/UserMenu.razor
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
@using BlazorState
@inject IStringLocalizer<SharedResource> L
@inherits BlazorStateComponent
@inherits FluxorComponent
<MudTooltip Arrow="true" Text="@L["User Profile"]">
<MudMenu AnchorOrigin="Origin.BottomRight"
Icon="@Icons.Material.Filled.PermIdentity"
Expand Down
Loading