Browse Source

Merge pull request #10609 from abpframework/maliming/AuthenticationStateProviderOnAuthenticationStateChanged

Update `AuthenticationStateProviderOnAuthenticationStateChanged`
pull/10612/head
liangshiwei 5 years ago
committed by GitHub
parent
commit
35dafd51b9
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/NavToolbar.razor.cs
  2. 25
      modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LoginDisplay.razor.cs

9
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.Web.BasicTheme/Themes/Basic/NavToolbar.razor.cs

@ -19,6 +19,12 @@ namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
private List<RenderFragment> ToolbarItemRenders { get; set; } = new List<RenderFragment>(); private List<RenderFragment> ToolbarItemRenders { get; set; } = new List<RenderFragment>();
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{
await GetToolbarItemRendersAsync();
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged;
}
private async Task GetToolbarItemRendersAsync()
{ {
var toolbar = await ToolbarManager.GetAsync(StandardToolbars.Main); var toolbar = await ToolbarManager.GetAsync(StandardToolbars.Main);
@ -33,12 +39,11 @@ namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
builder.CloseComponent(); builder.CloseComponent();
}); });
} }
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged;
} }
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task) private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task)
{ {
await GetToolbarItemRendersAsync();
await InvokeAsync(StateHasChanged); await InvokeAsync(StateHasChanged);
} }

25
modules/basic-theme/src/Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme/Themes/Basic/LoginDisplay.razor.cs

@ -15,35 +15,31 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic
[Inject] [Inject]
protected IMenuManager MenuManager { get; set; } protected IMenuManager MenuManager { get; set; }
[CanBeNull] [Inject]
protected AuthenticationStateProvider AuthenticationStateProvider; public AuthenticationStateProvider AuthenticationStateProvider { get; set; }
[CanBeNull] [CanBeNull]
protected SignOutSessionStateManager SignOutManager; protected SignOutSessionStateManager SignOutManager;
protected ApplicationMenu Menu { get; set; } protected ApplicationMenu Menu { get; set; }
protected override async Task OnInitializedAsync() protected override async Task OnInitializedAsync()
{ {
Menu = await MenuManager.GetAsync(StandardMenus.User); Menu = await MenuManager.GetAsync(StandardMenus.User);
Navigation.LocationChanged += OnLocationChanged; Navigation.LocationChanged += OnLocationChanged;
LazyGetService(ref AuthenticationStateProvider);
LazyGetService(ref SignOutManager); LazyGetService(ref SignOutManager);
if (AuthenticationStateProvider != null) AuthenticationStateProvider.AuthenticationStateChanged +=
{ AuthenticationStateProviderOnAuthenticationStateChanged;
AuthenticationStateProvider.AuthenticationStateChanged +=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
} }
protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e) protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e)
{ {
InvokeAsync(StateHasChanged); InvokeAsync(StateHasChanged);
} }
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task) private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task)
{ {
Menu = await MenuManager.GetAsync(StandardMenus.User); Menu = await MenuManager.GetAsync(StandardMenus.User);
@ -53,13 +49,10 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic
public void Dispose() public void Dispose()
{ {
Navigation.LocationChanged -= OnLocationChanged; Navigation.LocationChanged -= OnLocationChanged;
if (AuthenticationStateProvider != null) AuthenticationStateProvider.AuthenticationStateChanged -=
{ AuthenticationStateProviderOnAuthenticationStateChanged;
AuthenticationStateProvider.AuthenticationStateChanged -=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
} }
private async Task NavigateToAsync(string uri, string target = null) private async Task NavigateToAsync(string uri, string target = null)
{ {
if (target == "_blank") if (target == "_blank")

Loading…
Cancel
Save