fixed Article Editor double-load bug
This commit is contained in:
parent
85464def08
commit
670612500c
|
@ -6,6 +6,7 @@
|
||||||
@using System.Security.Claims
|
@using System.Security.Claims
|
||||||
|
|
||||||
@rendermode @(new InteractiveServerRenderMode(true))
|
@rendermode @(new InteractiveServerRenderMode(true))
|
||||||
|
@attribute [Authorize(Policy = "ArticleEditPermissions")]
|
||||||
|
|
||||||
@inject UserManager<ApplicationUser> UserManager
|
@inject UserManager<ApplicationUser> UserManager
|
||||||
@inject IStringLocalizer<ArticleEditor> Localizer
|
@inject IStringLocalizer<ArticleEditor> Localizer
|
||||||
|
@ -36,18 +37,22 @@
|
||||||
[CascadingParameter(Name = "TitlePostfix")]
|
[CascadingParameter(Name = "TitlePostfix")]
|
||||||
private string TitlePostfix { get; set; } = default!;
|
private string TitlePostfix { get; set; } = default!;
|
||||||
[CascadingParameter]
|
[CascadingParameter]
|
||||||
private Task<AuthenticationState>? AuthenticationState { get; set; }
|
private Task<AuthenticationState> AuthenticationState { get; set; } = default!;
|
||||||
|
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public Guid? Id { get; set; }
|
public Guid? Id { get; set; }
|
||||||
private ApplicationUser? User { get; set; }
|
private ApplicationUser? User { get; set; }
|
||||||
private ClaimsPrincipal? ClaimsUser { get; set; }
|
private ClaimsPrincipal? ClaimsUser { get; set; }
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync() {
|
protected override async Task OnAfterRenderAsync(bool firstRender) {
|
||||||
if (AuthenticationState is null) throw new ApplicationException("???");
|
if (firstRender) {
|
||||||
var state = await AuthenticationState;
|
if (User is not null) return;
|
||||||
ClaimsUser = state.User;
|
var state = await AuthenticationState;
|
||||||
var user = await UserManager.GetUserAsync(state.User);
|
ClaimsUser = state.User;
|
||||||
User = user ?? throw new ApplicationException("???2");
|
var user = await UserManager.GetUserAsync(state.User);
|
||||||
|
User = user ?? throw new ApplicationException("???2");
|
||||||
|
await InvokeAsync(StateHasChanged);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -128,7 +128,8 @@
|
||||||
|
|
||||||
protected override async Task OnInitializedAsync() {
|
protected override async Task OnInitializedAsync() {
|
||||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||||
Categories = await context.Set<Category>().IgnoreQueryFilters().OrderBy(c => c.Color).ToListAsync();
|
if (Categories.Count < 1)
|
||||||
|
Categories = await context.Set<Category>().IgnoreQueryFilters().OrderBy(c => c.Color).ToListAsync();
|
||||||
|
|
||||||
Article? article = null;
|
Article? article = null;
|
||||||
if (Id is not null) {
|
if (Id is not null) {
|
||||||
|
|
Loading…
Reference in a new issue