Wave/Wave/Components/Pages/ArticleEditor.razor

52 lines
1.5 KiB
Plaintext

@page "/article/new"
@page "/article/{id:guid}/edit"
@using Wave.Data
@using Microsoft.AspNetCore.Identity
@rendermode InteractiveServer
@attribute [Authorize(Policy = "ArticleEditOrReviewPermissions")]
@inject UserManager<ApplicationUser> UserManager
@inject IStringLocalizer<ArticleEditor> Localizer
<PageTitle>@(TitlePrefix + Localizer["EditorTitle"])</PageTitle>
@if (User is null) {
<h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["EditorTitle"]</h1>
<div class="flex place-content-center">
<span class="loading loading-spinner loading-lg"></span>
</div>
} else {
<ErrorBoundary>
<ChildContent>
<h1 class="text-3xl lg:text-5xl font-light mb-6 text-primary">@Localizer["EditorTitle"]</h1>
<Wave.Components.Pages.Partials.ArticleEditorPartial Id="@Id" User="@User" />
</ChildContent>
<ErrorContent>
<h1 class="text-3xl lg:text-5xl font-light mb-6">Not found</h1>
</ErrorContent>
</ErrorBoundary>
}
@code {
[CascadingParameter(Name = "TitlePrefix")]
private string TitlePrefix { get; set; } = default!;
[CascadingParameter]
private Task<AuthenticationState>? AuthenticationState { get; set; }
[Parameter]
public Guid? Id { get; set; }
private ApplicationUser? User { get; set; }
protected override async Task OnInitializedAsync() {
if (AuthenticationState is null) throw new ApplicationException("???");
var state = await AuthenticationState;
var user = await UserManager.GetUserAsync(state.User);
User = user ?? throw new ApplicationException("???2");
}
}