aboutsummaryrefslogtreecommitdiff
path: root/Hotline
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2024-01-08 15:18:00 -0800
committerDustin Mierau <dustin@mierau.me>2024-01-08 15:18:00 -0800
commitf87ae3b315e20ac31426782d7f40f8977a36e5b9 (patch)
tree7caa3fd1d798be23a7c27239ccc01ecb902160d0 /Hotline
parente9bae0328801d5a056f33beb0f764c6d35e518a2 (diff)
Add Markdown display for news articles to support rich text, images, links, tables, etc.
Diffstat (limited to 'Hotline')
-rw-r--r--Hotline/Models/NewsInfo.swift4
-rw-r--r--Hotline/macOS/NewsView.swift24
2 files changed, 16 insertions, 12 deletions
diff --git a/Hotline/Models/NewsInfo.swift b/Hotline/Models/NewsInfo.swift
index daab71f..f95cba1 100644
--- a/Hotline/Models/NewsInfo.swift
+++ b/Hotline/Models/NewsInfo.swift
@@ -15,6 +15,7 @@ enum NewsInfoType {
let categoryID: UUID?
let articleID: UInt?
+ let parentID: UInt?
let path: [String]
var expanded: Bool = false
@@ -27,6 +28,7 @@ enum NewsInfoType {
init(hotlineNewsCategory: HotlineNewsCategory) {
self.categoryID = hotlineNewsCategory.id
self.articleID = nil
+ self.parentID = nil
self.name = hotlineNewsCategory.name
self.count = UInt(hotlineNewsCategory.count)
self.path = hotlineNewsCategory.path
@@ -41,6 +43,8 @@ enum NewsInfoType {
init(hotlineNewsArticle: HotlineNewsArticle) {
self.articleID = UInt(hotlineNewsArticle.id)
+ self.parentID = hotlineNewsArticle.parentID == 0 ? nil : UInt(hotlineNewsArticle.parentID)
+ print(hotlineNewsArticle.parentID)
self.categoryID = nil
self.name = hotlineNewsArticle.title
self.count = 0
diff --git a/Hotline/macOS/NewsView.swift b/Hotline/macOS/NewsView.swift
index 45bae68..daeb45b 100644
--- a/Hotline/macOS/NewsView.swift
+++ b/Hotline/macOS/NewsView.swift
@@ -1,5 +1,5 @@
import SwiftUI
-import UniformTypeIdentifiers
+import MarkdownUI
struct NewsItemView: View {
@Environment(Hotline.self) private var model: Hotline
@@ -24,7 +24,7 @@ struct NewsItemView: View {
}()
var body: some View {
- HStack {
+ HStack(alignment: .center, spacing: 6) {
if news.type == .bundle || news.type == .category {
Button {
news.expanded.toggle()
@@ -40,15 +40,14 @@ struct NewsItemView: View {
.padding(.leading, 4)
}
else if news.type == .article {
-// HStack(alignment: .center) {
-// Text(Image(systemName: "quote.opening"))
-// .font(.system(size: 12))
-// .opacity(0.5)
-// .frame(alignment: .centerFirstTextBaseline)
-
-// Image(systemName: "quote.opening")
-// }
-// .frame(width: 14)
+ if news.parentID != nil {
+ Image(systemName: "arrowshape.turn.up.left.fill")
+ .resizable()
+ .renderingMode(.template)
+ .scaledToFit()
+ .frame(width: 10)
+ .foregroundStyle(.secondary)
+ }
}
Text(news.name)
.fontWeight((news.type == .bundle || news.type == .category) ? .bold : .regular)
@@ -203,7 +202,8 @@ struct NewsView: View {
Divider()
if let newsText = self.articleText {
- Text(newsText)
+ Markdown(newsText)
+// Text(newsText)
.textSelection(.enabled)
.lineSpacing(4)
.padding(.top, 16)