aboutsummaryrefslogtreecommitdiff
path: root/Hotline/iOS/NewsView.swift
diff options
context:
space:
mode:
Diffstat (limited to 'Hotline/iOS/NewsView.swift')
-rw-r--r--Hotline/iOS/NewsView.swift74
1 files changed, 38 insertions, 36 deletions
diff --git a/Hotline/iOS/NewsView.swift b/Hotline/iOS/NewsView.swift
index 460dcd3..72dd034 100644
--- a/Hotline/iOS/NewsView.swift
+++ b/Hotline/iOS/NewsView.swift
@@ -4,16 +4,16 @@ import UniformTypeIdentifiers
struct NewsItemView: View {
@Environment(Hotline.self) private var model: Hotline
@Environment(NewsItemSelection.self) private var selectedArticle: NewsItemSelection
-
+
let news: NewsInfo
-
+
static var dateFormatter: DateFormatter = {
var formatter = DateFormatter()
formatter.dateFormat = "MM/dd/yy, h:mm a"
formatter.timeZone = .gmt
return formatter
}()
-
+
static var relativeDateFormatter: RelativeDateTimeFormatter = {
var formatter = RelativeDateTimeFormatter()
formatter.unitsStyle = .abbreviated
@@ -21,9 +21,9 @@ struct NewsItemView: View {
formatter.formattingContext = .listItem
return formatter
}()
-
+
@State var expanded = false
-
+
var body: some View {
if news.count > 0 {
DisclosureGroup(isExpanded: $expanded) {
@@ -49,13 +49,12 @@ struct NewsItemView: View {
if !expanded {
return
}
-
+
Task {
await model.getNewsList(at: news.path)
}
}
- }
- else {
+ } else {
HStack(alignment: .firstTextBaseline) {
Text(Image(systemName: "quote.opening"))
Text(news.name)
@@ -66,13 +65,12 @@ struct NewsItemView: View {
Text("\(news.count)")
.lineLimit(1)
.foregroundStyle(.secondary)
- }
- else if let postAuthor = news.articleUsername {
-// Text("\(NewsItemView.relativeDateFormatter.localizedString(for: postDate, relativeTo: Date.now))")
+ } else if let postAuthor = news.articleUsername {
+ // Text("\(NewsItemView.relativeDateFormatter.localizedString(for: postDate, relativeTo: Date.now))")
Text(postAuthor)
.foregroundStyle(.secondary)
.truncationMode(.tail)
-// .frame(maxWidth: 50)
+ // .frame(maxWidth: 50)
.font(.caption)
.lineLimit(1)
}
@@ -90,7 +88,7 @@ struct NewsItemView: View {
@Observable
class NewsItemSelection: Equatable {
var selectedArticle: NewsInfo? = nil
-
+
static func == (lhs: NewsItemSelection, rhs: NewsItemSelection) -> Bool {
return lhs.selectedArticle == rhs.selectedArticle
}
@@ -99,25 +97,24 @@ class NewsItemSelection: Equatable {
struct NewsView: View {
@Environment(Hotline.self) private var model: Hotline
@Environment(\.colorScheme) var colorScheme
-
+
@State private var fetched = false
@State private var selectedCategory: NewsInfo? = nil
@State private var topListHeight: CGFloat = 280
@State private var dividerHeight: CGFloat = 30
-
+
@State private var articleSelection = NewsItemSelection()
@State private var articleText = ""
-
-// @State private var selectedArticleID: UInt?
-
+
+ // @State private var selectedArticleID: UInt?
+
var articleList: some View {
VStack(spacing: 0) {
if model.news.count == 0 {
Text("No News Available")
.font(.headline)
.opacity(0.3)
- }
- else {
+ } else {
List(model.news) { category in
NewsItemView(news: category)
.frame(height: 38)
@@ -128,10 +125,10 @@ struct NewsView: View {
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(Color(uiColor: .systemGroupedBackground))
-
+
// .listStyle(.plain)
}
-
+
var body: some View {
NavigationStack {
VStack(spacing: 0) {
@@ -140,19 +137,21 @@ struct NewsView: View {
.frame(minHeight: topListHeight)
.onChange(of: self.articleSelection.selectedArticle) {
self.articleText = ""
- if
- let article = self.articleSelection.selectedArticle,
+ if let article = self.articleSelection.selectedArticle,
let articleFlavor = article.articleFlavors?.first,
- let articleID = article.articleID {
+ let articleID = article.articleID
+ {
Task {
- if let articleText = await self.model.getNewsArticle(id: articleID, at: article.path, flavor: articleFlavor) {
+ if let articleText = await self.model.getNewsArticle(
+ id: articleID, at: article.path, flavor: articleFlavor)
+ {
self.articleText = articleText
}
}
}
-// print("SELECTED ARTICLE", articleSelection.selectedArticle?.name)
+ // print("SELECTED ARTICLE", articleSelection.selectedArticle?.name)
}
-
+
// Movable Divider
VStack(alignment: .center) {
Divider()
@@ -165,7 +164,9 @@ struct NewsView: View {
}
Spacer()
}
- .background(colorScheme == .dark ? Color(white: 0.1) : Color(uiColor: UIColor.systemBackground))
+ .background(
+ colorScheme == .dark ? Color(white: 0.1) : Color(uiColor: UIColor.systemBackground)
+ )
.frame(maxWidth: .infinity)
.frame(height: dividerHeight)
.gesture(
@@ -175,11 +176,11 @@ struct NewsView: View {
topListHeight = max(min(topListHeight + delta, 500), 50)
}
)
-
+
// Reader View
ScrollView(.vertical) {
VStack(alignment: .leading) {
-
+
if let news = self.articleSelection.selectedArticle {
if let poster = news.articleUsername, let postDate = news.articleDate {
HStack(alignment: .firstTextBaseline) {
@@ -189,7 +190,7 @@ struct NewsView: View {
.lineLimit(1)
.truncationMode(.tail)
.textSelection(.enabled)
-// .padding()
+ // .padding()
Spacer()
Text("\(NewsItemView.dateFormatter.string(from: postDate))")
.foregroundStyle(.secondary)
@@ -198,16 +199,16 @@ struct NewsView: View {
.textSelection(.enabled)
}
.padding(.bottom, 8)
-
+
Divider()
.padding(.bottom, 16)
}
-
+
Text(news.name).font(.title3).fontWeight(.medium)
.textSelection(.enabled)
.padding(.bottom, 8)
}
-
+
Text(self.articleText)
.multilineTextAlignment(.leading)
.textSelection(.enabled)
@@ -216,7 +217,8 @@ struct NewsView: View {
.padding()
}
.scrollBounceBehavior(.basedOnSize)
- .background(colorScheme == .dark ? Color(white: 0.1) : Color(uiColor: UIColor.systemBackground))
+ .background(
+ colorScheme == .dark ? Color(white: 0.1) : Color(uiColor: UIColor.systemBackground))
}
.task {
if !fetched {