From 98c923b07b958054c7c471591dca6f6e20d48520 Mon Sep 17 00:00:00 2001 From: Oliver Booth Date: Sat, 27 Apr 2024 17:00:20 +0100 Subject: [PATCH] style: hide empty section for articles with no other parts --- OliverBooth/Data/Web/ITutorialArticle.cs | 6 +++ OliverBooth/Data/Web/TutorialArticle.cs | 6 +++ OliverBooth/Pages/Tutorials/Article.cshtml | 59 ++++++++++++---------- 3 files changed, 43 insertions(+), 28 deletions(-) diff --git a/OliverBooth/Data/Web/ITutorialArticle.cs b/OliverBooth/Data/Web/ITutorialArticle.cs index bbb398a..5e2f6c6 100644 --- a/OliverBooth/Data/Web/ITutorialArticle.cs +++ b/OliverBooth/Data/Web/ITutorialArticle.cs @@ -31,6 +31,12 @@ public interface ITutorialArticle /// The ID of the folder. int Folder { get; } + /// + /// Gets a value indicating whether this article is part of a multi-part series. + /// + /// if this article has additional parts; otherwise, . + bool HasOtherParts { get; } + /// /// Gets the ID of this article. /// diff --git a/OliverBooth/Data/Web/TutorialArticle.cs b/OliverBooth/Data/Web/TutorialArticle.cs index 88b21f1..52fbb90 100644 --- a/OliverBooth/Data/Web/TutorialArticle.cs +++ b/OliverBooth/Data/Web/TutorialArticle.cs @@ -1,3 +1,5 @@ +using System.ComponentModel.DataAnnotations.Schema; + namespace OliverBooth.Data.Web; /// @@ -17,6 +19,10 @@ internal sealed class TutorialArticle : IEquatable, ITutorialAr /// public int Folder { get; private set; } + /// + [NotMapped] + public bool HasOtherParts => NextPart is not null || PreviousPart is not null; + /// public int Id { get; private set; } diff --git a/OliverBooth/Pages/Tutorials/Article.cshtml b/OliverBooth/Pages/Tutorials/Article.cshtml index 9f0aca4..7919c37 100644 --- a/OliverBooth/Pages/Tutorials/Article.cshtml +++ b/OliverBooth/Pages/Tutorials/Article.cshtml @@ -60,36 +60,39 @@ @Html.Raw(TutorialService.RenderArticle(article)) -
+@if (article.HasOtherParts) +{ +
-
-
- @if (article.PreviousPart is { } previousPartId && - TutorialService.TryGetArticle(previousPartId, out ITutorialArticle? previousPart) && - previousPart.Visibility == Visibility.Published) - { - Previous Part -

- - @previousPart.Title - -

- } +
+
+ @if (article.PreviousPart is { } previousPartId && + TutorialService.TryGetArticle(previousPartId, out ITutorialArticle? previousPart) && + previousPart.Visibility == Visibility.Published) + { + Previous Part +

+ + @previousPart.Title + +

+ } +
+
+ @if (article.NextPart is { } nextPartId && + TutorialService.TryGetArticle(nextPartId, out ITutorialArticle? nextPart) && + nextPart.Visibility == Visibility.Published) + { + Next Part +

+ + @nextPart.Title + +

+ } +
-
- @if (article.NextPart is { } nextPartId && - TutorialService.TryGetArticle(nextPartId, out ITutorialArticle? nextPart) && - nextPart.Visibility == Visibility.Published) - { - Next Part -

- - @nextPart.Title - -

- } -
-
+}