Improved Article Card and Article Card List
This commit is contained in:
parent
8ff3ff922c
commit
adf87ddc16
|
@ -1,14 +1,13 @@
|
||||||
@using Wave.Data
|
@using Wave.Data
|
||||||
@using Humanizer
|
@using Humanizer
|
||||||
|
|
||||||
|
@if (HasArticleLink) {
|
||||||
|
<ArticleLink Article="Article">
|
||||||
<article class="card card-side card-compact bg-base-200 text-base-content">
|
<article class="card card-side card-compact bg-base-200 text-base-content">
|
||||||
<figure class="shrink-0 max-md:!hidden sm:max-w-40">
|
<figure class="shrink-0 max-md:!hidden sm:max-w-40">
|
||||||
<ArticleLink Article="Article">
|
<img src="/api/user/pfp/@Article.Author.Id?size=600" alt="" width="600">
|
||||||
<img src="/api/user/pfp/@Article.Author.Id" alt="" width="800">
|
|
||||||
</ArticleLink>
|
|
||||||
</figure>
|
</figure>
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<ArticleLink Article="Article">
|
|
||||||
<h2 class="card-title line-clamp-1">@Article.Title</h2>
|
<h2 class="card-title line-clamp-1">@Article.Title</h2>
|
||||||
<small>
|
<small>
|
||||||
@Article.PublishDate.ToString("d")
|
@Article.PublishDate.ToString("d")
|
||||||
|
@ -19,7 +18,6 @@
|
||||||
<p class="@(Article.Categories.Count > 0 ? "line-clamp-2" : "line-clamp-4")">
|
<p class="@(Article.Categories.Count > 0 ? "line-clamp-2" : "line-clamp-4")">
|
||||||
@Article.BodyPlain[..Math.Min(1000, Article.BodyPlain.Length)]
|
@Article.BodyPlain[..Math.Min(1000, Article.BodyPlain.Length)]
|
||||||
</p>
|
</p>
|
||||||
</ArticleLink>
|
|
||||||
@if (Action is not null) {
|
@if (Action is not null) {
|
||||||
<div class="card-actions w-full">
|
<div class="card-actions w-full">
|
||||||
@Action(Article)
|
@Action(Article)
|
||||||
|
@ -27,16 +25,49 @@
|
||||||
} else if (Article.Categories.Count > 0) {
|
} else if (Article.Categories.Count > 0) {
|
||||||
<div class="card-actions flex flex-wrap gap-2">
|
<div class="card-actions flex flex-wrap gap-2">
|
||||||
@foreach (var category in Article.Categories.OrderBy(c => c.Color)) {
|
@foreach (var category in Article.Categories.OrderBy(c => c.Color)) {
|
||||||
<CategoryBadgeComponent Category="category" />
|
<CategoryBadgeComponent HasCategoryLink="false" Category="category" />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
</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 {
|
@code {
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public required Article Article { get; set; }
|
public required Article Article { get; set; }
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public RenderFragment<Article>? Action { get; set; }
|
public RenderFragment<Article>? Action { get; set; }
|
||||||
|
[Parameter]
|
||||||
|
public bool HasArticleLink { get; set; } = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
} else {
|
} else {
|
||||||
<div class="flex flex-col gap-4">
|
<div class="flex flex-col gap-4">
|
||||||
@foreach (var article in Articles.OrderByDescending(a => a.PublishDate)) {
|
@foreach (var article in Articles.OrderByDescending(a => a.PublishDate)) {
|
||||||
<ArticleCard Article="article" Action="Action" />
|
<ArticleCard Article="article" Action="Action" HasArticleLink="HasArticleLink" />
|
||||||
}
|
}
|
||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
@ -15,4 +15,6 @@
|
||||||
public required IList<Article> Articles { get; set; } = [];
|
public required IList<Article> Articles { get; set; } = [];
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public RenderFragment<Article>? Action { get; set; }
|
public RenderFragment<Article>? Action { get; set; }
|
||||||
|
[Parameter]
|
||||||
|
public bool HasArticleLink { get; set; } = true;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,14 +3,21 @@
|
||||||
@using System.Net
|
@using System.Net
|
||||||
|
|
||||||
<!-- badge badge-info badge-warning badge-error badge-primary badge-secondary badge-neutral badge-accent -->
|
<!-- badge badge-info badge-warning badge-error badge-primary badge-secondary badge-neutral badge-accent -->
|
||||||
|
@if (HasCategoryLink) {
|
||||||
<a href="/category/@WebUtility.UrlEncode(Category.Name)" class="badge badge-@CategoryUtilities.GetCssClassPostfixForColor(Category.Color)" @attributes="AdditionalAttributes">
|
<a href="/category/@WebUtility.UrlEncode(Category.Name)" class="badge badge-@CategoryUtilities.GetCssClassPostfixForColor(Category.Color)" @attributes="AdditionalAttributes">
|
||||||
@Category.Name
|
@Category.Name
|
||||||
</a>
|
</a>
|
||||||
|
} else {
|
||||||
|
<span class="badge badge-@CategoryUtilities.GetCssClassPostfixForColor(Category.Color)" @attributes="AdditionalAttributes">
|
||||||
|
@Category.Name
|
||||||
|
</span>
|
||||||
|
}
|
||||||
|
|
||||||
@code {
|
@code {
|
||||||
[Parameter]
|
[Parameter]
|
||||||
public required Category Category { get; set; }
|
public required Category Category { get; set; }
|
||||||
|
[Parameter]
|
||||||
|
public bool HasCategoryLink { get; set; } = true;
|
||||||
[Parameter(CaptureUnmatchedValues = true)]
|
[Parameter(CaptureUnmatchedValues = true)]
|
||||||
public Dictionary<string, object>? AdditionalAttributes { get; set; }
|
public Dictionary<string, object>? AdditionalAttributes { get; set; }
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue