96 lines
3.2 KiB
Plaintext
96 lines
3.2 KiB
Plaintext
@page "/article/{id:guid}"
|
|
@using Microsoft.EntityFrameworkCore
|
|
@using Wave.Data
|
|
@using Humanizer
|
|
@using System.Globalization
|
|
|
|
@inject IDbContextFactory<ApplicationDbContext> ContextFactory;
|
|
@inject IStringLocalizer<ArticleView> Localizer
|
|
|
|
<PageTitle>@(TitlePrefix + Article.Title)</PageTitle>
|
|
|
|
<h1 class="text-3xl lg:text-5xl font-light">@Article.Title</h1>
|
|
<p class="mb-3">
|
|
<small class="text-sm text-neutral-content">
|
|
<time datetime="@Article.PublishDate.ToString("u")"
|
|
title="@Article.PublishDate.ToString("g")">
|
|
@Article.PublishDate.Humanize()
|
|
</time>
|
|
@if (Article.LastModified is not null) {
|
|
<time datetime="@Article.LastModified.Value.ToString("u")"
|
|
title="@Article.LastModified.Value.ToString("g")">
|
|
 (@Localizer["ModifiedOn"] @Article.LastModified.Humanize())
|
|
</time>
|
|
}
|
|
</small>
|
|
</p>
|
|
<AuthorizeView Policy="ArticleEditPermissions">
|
|
<Authorized>
|
|
<a class="btn btn-info mb-3" href="article/@Article.Id/edit">Edit</a>
|
|
</Authorized>
|
|
</AuthorizeView>
|
|
|
|
<hr class="my-3" />
|
|
|
|
<article class="prose prose-neutral max-w-none mb-6">
|
|
@Content
|
|
</article>
|
|
|
|
<hr class="my-3" />
|
|
|
|
@if (!string.IsNullOrWhiteSpace(Article.Author.AboutTheAuthor)) {
|
|
<section class="mb-2">
|
|
<h2 class="text-2xl lg:text-4xl mb-3">About The Author</h2>
|
|
<div class="card sm:card-side card-compact bg-neutral text-neutral-content rounded shadow">
|
|
<figure class="sm:max-w-32">
|
|
<img src="/api/user/pfp/@Article.Author.Id" alt="" width="800">
|
|
</figure>
|
|
<div class="card-body">
|
|
<h3 class="card-title">@Article.Author.Name</h3>
|
|
<p>
|
|
@Article.Author.AboutTheAuthor
|
|
</p>
|
|
</div>
|
|
</div>
|
|
</section>
|
|
}
|
|
|
|
<div class="flex gap-2">
|
|
@if (string.IsNullOrWhiteSpace(Article.Author.AboutTheAuthor)) {
|
|
<ProfilePill Profile="Article.Author" RoleTag="@Localizer["Author"]"/>
|
|
}
|
|
@if (Article.Reviewer is not null && Article.Reviewer.Id != Article.Author.Id) {
|
|
<ProfilePill Profile="Article.Reviewer" RoleTag="@Localizer["Reviewer"]"/>
|
|
}
|
|
</div>
|
|
|
|
|
|
@code {
|
|
[CascadingParameter(Name = "TitlePrefix")]
|
|
private string TitlePrefix { get; set; } = default!;
|
|
|
|
[Parameter]
|
|
public Guid Id { get; set; }
|
|
|
|
private Article Article { get; set; } = null!;
|
|
private MarkupString Content => new(Article.BodyHtml);
|
|
|
|
protected override async Task OnInitializedAsync() {
|
|
// We need blocking calls here, bc otherwise Blazor will execute Render in parallel,
|
|
// running into a null pointer on the Article property and panicking
|
|
|
|
// ReSharper disable once MethodHasAsyncOverload
|
|
await using var context = ContextFactory.CreateDbContext();
|
|
// ReSharper disable once MethodHasAsyncOverload
|
|
var now = DateTimeOffset.UtcNow;
|
|
Article = context.Set<Article>()
|
|
.Include(a => a.Author)
|
|
.Include(a => a.Reviewer)
|
|
.Where(a => a.Status >= ArticleStatus.Published && a.PublishDate <= now)
|
|
.First(a => a.Id == Id);
|
|
|
|
if (Article is null) throw new ApplicationException("Article not found.");
|
|
}
|
|
|
|
}
|