Skip to content

Commit 0c5ef34

Browse files
State object for SideBar
1 parent a674d8d commit 0c5ef34

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using BlazorState;
2+
using MediatR;
3+
using System;
4+
using System.Threading;
5+
using System.Threading.Tasks;
6+
7+
namespace Blazor.AdminLte
8+
{
9+
public partial class SideBarState : State<SideBarState>
10+
{
11+
public string ActiveMenu { get; set; }
12+
13+
public NavLinkState GetState(string item)
14+
{
15+
if (item == ActiveMenu)
16+
return NavLinkState.Active;
17+
else
18+
return NavLinkState.Inactive;
19+
}
20+
21+
public override void Initialize()
22+
{
23+
24+
}
25+
26+
public class SelectMenuItemAction : IAction
27+
{
28+
public string Id { get; set; }
29+
}
30+
31+
public class SelectMenuItemHandler : ActionHandler<SelectMenuItemAction>
32+
{
33+
public SelectMenuItemHandler(IStore aStore) : base(aStore) { }
34+
35+
SideBarState State => Store.GetState<SideBarState>();
36+
public override Task<Unit> Handle(SelectMenuItemAction aAction, CancellationToken aCancellationToken)
37+
{
38+
State.ActiveMenu = aAction.Id;
39+
return Unit.Task;
40+
}
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)