From 958d410ddc615b94ac7a118a9037a42eb9c5c582 Mon Sep 17 00:00:00 2001 From: Otavio Cordeiro Date: Fri, 19 Dec 2025 21:10:33 +0100 Subject: [PATCH] Show status of weblog entry in list of posts --- .../Fixtures/WeblogEntryViewModelMother.swift | 2 +- .../Views/Weblog Entry/WeblogEntryView.swift | 15 +++++++++++++++ .../Views/Weblog Entry/WeblogEntryViewModel.swift | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/Packages/Weblog/Sources/Weblog/Fixtures/WeblogEntryViewModelMother.swift b/Packages/Weblog/Sources/Weblog/Fixtures/WeblogEntryViewModelMother.swift index 9f3eb71..45db3e3 100644 --- a/Packages/Weblog/Sources/Weblog/Fixtures/WeblogEntryViewModelMother.swift +++ b/Packages/Weblog/Sources/Weblog/Fixtures/WeblogEntryViewModelMother.swift @@ -12,7 +12,7 @@ id: "blogpostID", title: "This is a test", body: "This is just a test post. ", - status: isDraft ? "draft" : "published", + status: isDraft ? "draft" : "live", timestamp: 12_312_312, address: "otaviocc", location: "/2022/12/my-weblog-post", diff --git a/Packages/Weblog/Sources/Weblog/Views/Weblog Entry/WeblogEntryView.swift b/Packages/Weblog/Sources/Weblog/Views/Weblog Entry/WeblogEntryView.swift index 324efcc..9ac7c4b 100644 --- a/Packages/Weblog/Sources/Weblog/Views/Weblog Entry/WeblogEntryView.swift +++ b/Packages/Weblog/Sources/Weblog/Views/Weblog Entry/WeblogEntryView.swift @@ -26,6 +26,10 @@ struct WeblogEntryView: View { VStack(alignment: .leading, spacing: 4) { makeHeaderView() makeContentView() + + if viewModel.showStatus { + makeStatusView() + } } .frame( maxWidth: .infinity, @@ -65,6 +69,17 @@ struct WeblogEntryView: View { .foregroundColor(.primary) } + @ViewBuilder + private func makeStatusView() -> some View { + HStack { + Spacer() + Text(viewModel.status) + .textCase(.uppercase) + .font(.caption) + .foregroundColor(.accentColor) + } + } + @ViewBuilder private func makeContextualMenu() -> some View { makeEditEntryMenuItem() diff --git a/Packages/Weblog/Sources/Weblog/Views/Weblog Entry/WeblogEntryViewModel.swift b/Packages/Weblog/Sources/Weblog/Views/Weblog Entry/WeblogEntryViewModel.swift index add946e..0d65186 100644 --- a/Packages/Weblog/Sources/Weblog/Views/Weblog Entry/WeblogEntryViewModel.swift +++ b/Packages/Weblog/Sources/Weblog/Views/Weblog Entry/WeblogEntryViewModel.swift @@ -34,8 +34,8 @@ final class WeblogEntryViewModel: Identifiable { ) } - var isLive: Bool { - status == "live" + var showStatus: Bool { + status.lowercased() != "live" } private let repository: any WeblogRepositoryProtocol