Improved Article Card and Article Card List

This commit is contained in:
Mia Rose Winter 2024-03-25 13:12:52 +01:00
parent 8ff3ff922c
commit adf87ddc16
Signed by: miawinter
GPG key ID: 4B6F6A83178F595E
3 changed files with 67 additions and 27 deletions

View file

@ -1,14 +1,13 @@
@using Wave.Data
@using Humanizer
<article class="card card-side card-compact bg-base-200 text-base-content">
<figure class="shrink-0 max-md:!hidden sm:max-w-40">
@if (HasArticleLink) {
<ArticleLink Article="Article">
<img src="/api/user/pfp/@Article.Author.Id" alt="" width="800">
</ArticleLink>
<article class="card card-side card-compact bg-base-200 text-base-content">
<figure class="shrink-0 max-md:!hidden sm:max-w-40">
<img src="/api/user/pfp/@Article.Author.Id?size=600" alt="" width="600">
</figure>
<div class="card-body">
<ArticleLink Article="Article">
<h2 class="card-title line-clamp-1">@Article.Title</h2>
<small>
@Article.PublishDate.ToString("d")
@ -19,7 +18,6 @@
<p class="@(Article.Categories.Count > 0 ? "line-clamp-2" : "line-clamp-4")">
@Article.BodyPlain[..Math.Min(1000, Article.BodyPlain.Length)]
</p>
</ArticleLink>
@if (Action is not null) {
<div class="card-actions w-full">
@Action(Article)
@ -27,16 +25,49 @@
} else if (Article.Categories.Count > 0) {
<div class="card-actions flex flex-wrap gap-2">
@foreach (var category in Article.Categories.OrderBy(c => c.Color)) {
<CategoryBadgeComponent Category="category" />
<CategoryBadgeComponent HasCategoryLink="false" Category="category" />
}
</div>
}
</div>
</article>
</article>
</ArticleLink>
} else {
<article class="card card-side card-compact bg-base-200 text-base-content">
<figure class="shrink-0 max-md:!hidden sm:max-w-40">
<img src="/api/user/pfp/@Article.Author.Id?size=600" alt="" width="600">
</figure>
<div class="card-body">
<h2 class="card-title line-clamp-1">@Article.Title</h2>
<small>
@Article.PublishDate.ToString("d")
@if (Article.Status is not ArticleStatus.Published) {
<span class="badge badge-sm badge-warning ml-2">@Article.Status.Humanize()</span>
}
</small>
<p class="@(Article.Categories.Count > 0 ? "line-clamp-2" : "line-clamp-4")">
@Article.BodyPlain[..Math.Min(1000, Article.BodyPlain.Length)]
</p>
@if (Action is not null) {
<div class="card-actions w-full">
@Action(Article)
</div>
} else if (Article.Categories.Count > 0) {
<div class="card-actions flex flex-wrap gap-2">
@foreach (var category in Article.Categories.OrderBy(c => c.Color)) {
<CategoryBadgeComponent HasCategoryLink="false" Category="category" />
}
</div>
}
</div>
</article>
}
@code {
[Parameter]
public required Article Article { get; set; }
[Parameter]
public RenderFragment<Article>? Action { get; set; }
[Parameter]
public bool HasArticleLink { get; set; } = true;
}

View file

@ -5,7 +5,7 @@
} else {
<div class="flex flex-col gap-4">
@foreach (var article in Articles.OrderByDescending(a => a.PublishDate)) {
<ArticleCard Article="article" Action="Action" />
<ArticleCard Article="article" Action="Action" HasArticleLink="HasArticleLink" />
}
</div>
}
@ -15,4 +15,6 @@
public required IList<Article> Articles { get; set; } = [];
[Parameter]
public RenderFragment<Article>? Action { get; set; }
[Parameter]
public bool HasArticleLink { get; set; } = true;
}

View file

@ -3,14 +3,21 @@
@using System.Net
<!-- badge badge-info badge-warning badge-error badge-primary badge-secondary badge-neutral badge-accent -->
<a href="/category/@WebUtility.UrlEncode(Category.Name)" class="badge badge-@CategoryUtilities.GetCssClassPostfixForColor(Category.Color)" @attributes="AdditionalAttributes">
@if (HasCategoryLink) {
<a href="/category/@WebUtility.UrlEncode(Category.Name)" class="badge badge-@CategoryUtilities.GetCssClassPostfixForColor(Category.Color)" @attributes="AdditionalAttributes">
@Category.Name
</a>
</a>
} else {
<span class="badge badge-@CategoryUtilities.GetCssClassPostfixForColor(Category.Color)" @attributes="AdditionalAttributes">
@Category.Name
</span>
}
@code {
[Parameter]
public required Category Category { get; set; }
[Parameter]
public bool HasCategoryLink { get; set; } = true;
[Parameter(CaptureUnmatchedValues = true)]
public Dictionary<string, object>? AdditionalAttributes { get; set; }
}