aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/NewsItemView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline/macOS/NewsItemView.swift')
-rw-r--r--Hotline/macOS/NewsItemView.swift97
1 files changed, 51 insertions, 46 deletions
diff --git a/Hotline/macOS/NewsItemView.swift b/Hotline/macOS/NewsItemView.swift
index fc20e61..ff7495b 100644
--- a/Hotline/macOS/NewsItemView.swift
+++ b/Hotline/macOS/NewsItemView.swift
@@ -2,10 +2,10 @@ import SwiftUI
struct NewsItemView: View {
@Environment(Hotline.self) private var model: Hotline
-
+
var news: NewsInfo
let depth: Int
-
+
static var dateFormatter: DateFormatter = {
var dateFormatter = DateFormatter()
dateFormatter.dateStyle = .long
@@ -13,7 +13,7 @@ struct NewsItemView: View {
dateFormatter.timeZone = .gmt
return dateFormatter
}()
-
+
static var relativeDateFormatter: RelativeDateTimeFormatter = {
var formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .full
@@ -21,7 +21,7 @@ struct NewsItemView: View {
formatter.formattingContext = .listItem
return formatter
}()
-
+
var body: some View {
HStack(alignment: .center, spacing: 0) {
if news.expandable {
@@ -38,18 +38,17 @@ struct NewsItemView: View {
.frame(width: 10)
.padding(.leading, 4)
.padding(.trailing, 8)
- }
- else {
+ } else {
Spacer()
.frame(width: 10)
.padding(.leading, 4)
.padding(.trailing, 8)
}
-
+
// Tree indent
Spacer()
.frame(width: (CGFloat(depth) * 22))
-
+
switch news.type {
case .category:
Image("News Category")
@@ -64,60 +63,61 @@ struct NewsItemView: View {
case .article:
EmptyView()
}
-
+
Text(news.name)
- .fontWeight((news.type == .bundle || news.type == .category || !news.read) ? .semibold : .regular)
+ .fontWeight(
+ (news.type == .bundle || news.type == .category || !news.read) ? .semibold : .regular
+ )
.lineLimit(1)
.truncationMode(.tail)
-
+
if news.type == .article && news.articleUsername != nil {
Text(news.articleUsername!)
.foregroundStyle(.secondary)
.lineLimit(1)
.padding(.leading, 8)
}
-
+
Spacer()
-
+
if news.type == .category && news.count > 0 {
Text("^[\(news.count) Post](inflect: true)")
.lineLimit(1)
.foregroundStyle(.secondary)
.padding(.trailing, 8)
- }
- else if news.type == .bundle && news.count > 0 {
+ } else if news.type == .bundle && news.count > 0 {
Text("^[\(news.count) Category](inflect: true)")
.lineLimit(1)
.foregroundStyle(.secondary)
.padding(.trailing, 8)
}
-// if news.type == .bundle {
-// Text("\(news.count)")
-// .lineLimit(1)
-// .foregroundStyle(.tertiary)
-// .padding(.trailing, 8)
-
-// ZStack {
-// Text("^[\(news.count) \(news.type == .bundle ? "Category" : "Post")](inflect: true)")
-// Text("\(news.count)")
-// .foregroundStyle(.clear)
-//// .font(.caption)
-// .lineLimit(1)
-// .padding([.leading, .trailing], 8)
-// .padding([.top, .bottom], 2)
-// .background(.secondary)
-// .clipShape(Capsule())
-//
-// Text("\(news.count)")
-// .foregroundStyle(.white)
-//// .font(.caption)
-// .lineLimit(1)
-// .padding([.leading, .trailing], 8)
-// .padding([.top, .bottom], 2)
-// .blendMode(.destinationOut)
-// }
-// .drawingGroup(opaque: false)
-// }
+ // if news.type == .bundle {
+ // Text("\(news.count)")
+ // .lineLimit(1)
+ // .foregroundStyle(.tertiary)
+ // .padding(.trailing, 8)
+
+ // ZStack {
+ // Text("^[\(news.count) \(news.type == .bundle ? "Category" : "Post")](inflect: true)")
+ // Text("\(news.count)")
+ // .foregroundStyle(.clear)
+ //// .font(.caption)
+ // .lineLimit(1)
+ // .padding([.leading, .trailing], 8)
+ // .padding([.top, .bottom], 2)
+ // .background(.secondary)
+ // .clipShape(Capsule())
+ //
+ // Text("\(news.count)")
+ // .foregroundStyle(.white)
+ //// .font(.caption)
+ // .lineLimit(1)
+ // .padding([.leading, .trailing], 8)
+ // .padding([.top, .bottom], 2)
+ // .blendMode(.destinationOut)
+ // }
+ // .drawingGroup(opaque: false)
+ // }
else if news.type == .article && news.articleUsername != nil {
if let d = news.articleDate {
Text(NewsItemView.relativeDateFormatter.localizedString(for: d, relativeTo: Date.now))
@@ -132,12 +132,12 @@ struct NewsItemView: View {
guard news.expanded, news.type == .bundle || news.type == .category else {
return
}
-
+
Task {
await model.getNewsList(at: news.path)
}
}
-
+
if news.expanded {
ForEach(news.children.reversed(), id: \.self) { childNews in
NewsItemView(news: childNews, depth: self.depth + 1).tag(childNews.id)
@@ -147,6 +147,11 @@ struct NewsItemView: View {
}
#Preview {
- NewsItemView(news: NewsInfo(hotlineNewsArticle: HotlineNewsArticle(id: 0, parentID: 0, flags: 0, title: "Title", username: "username", date: Date.now, flavors: [("", 1)], path: ["Guest"])), depth: 0)
- .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient()))
+ NewsItemView(
+ news: NewsInfo(
+ hotlineNewsArticle: HotlineNewsArticle(
+ id: 0, parentID: 0, flags: 0, title: "Title", username: "username", date: Date.now,
+ flavors: [("", 1)], path: ["Guest"])), depth: 0
+ )
+ .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient()))
}