Browse Source

Update `AuthenticationStateProviderOnAuthenticationStateChanged`

pull/10609/head
maliming 5 years ago
parent
commit
1d77887faa
No known key found for this signature in database GPG Key ID: 96224957E51C89E
  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>();
protected override async Task OnInitializedAsync()
{
await GetToolbarItemRendersAsync();
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged;
}
private async Task GetToolbarItemRendersAsync()
{
var toolbar = await ToolbarManager.GetAsync(StandardToolbars.Main);
@ -33,12 +39,11 @@ namespace Volo.Abp.AspNetCore.Components.Web.BasicTheme.Themes.Basic
builder.CloseComponent();
});
}
AuthenticationStateProvider.AuthenticationStateChanged += AuthenticationStateProviderOnAuthenticationStateChanged;
}
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task)
{
await GetToolbarItemRendersAsync();
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]
protected IMenuManager MenuManager { get; set; }
[CanBeNull]
protected AuthenticationStateProvider AuthenticationStateProvider;
[Inject]
public AuthenticationStateProvider AuthenticationStateProvider { get; set; }
[CanBeNull]
protected SignOutSessionStateManager SignOutManager;
protected ApplicationMenu Menu { get; set; }
protected override async Task OnInitializedAsync()
{
Menu = await MenuManager.GetAsync(StandardMenus.User);
Navigation.LocationChanged += OnLocationChanged;
LazyGetService(ref AuthenticationStateProvider);
LazyGetService(ref SignOutManager);
if (AuthenticationStateProvider != null)
{
AuthenticationStateProvider.AuthenticationStateChanged +=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
AuthenticationStateProvider.AuthenticationStateChanged +=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
protected virtual void OnLocationChanged(object sender, LocationChangedEventArgs e)
{
InvokeAsync(StateHasChanged);
}
private async void AuthenticationStateProviderOnAuthenticationStateChanged(Task<AuthenticationState> task)
{
Menu = await MenuManager.GetAsync(StandardMenus.User);
@ -53,13 +49,10 @@ namespace Volo.Abp.AspNetCore.Components.WebAssembly.BasicTheme.Themes.Basic
public void Dispose()
{
Navigation.LocationChanged -= OnLocationChanged;
if (AuthenticationStateProvider != null)
{
AuthenticationStateProvider.AuthenticationStateChanged -=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
AuthenticationStateProvider.AuthenticationStateChanged -=
AuthenticationStateProviderOnAuthenticationStateChanged;
}
private async Task NavigateToAsync(string uri, string target = null)
{
if (target == "_blank")

Loading…
Cancel
Save