aboutsummaryrefslogtreecommitdiff
path: root/Hotline/macOS/News
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2025-11-07 10:19:42 -0800
committerDustin Mierau <dustin@mierau.me>2025-11-07 10:19:42 -0800
commit87f08cf60a5d7c1cf618463916cbac4dab88e0f8 (patch)
treec15a94443801beff5fcb8ac5d5dbc8276726ee39 /Hotline/macOS/News
parentbcf36ef614aa46ae3d8e714add470f749fdf3714 (diff)
Massive refactor of transfer cients (new folder upload implementation), brand new async version of NetSocket, and a rewritten Hotline view model. New cross-server transfers UI.
Diffstat (limited to 'Hotline/macOS/News')
-rw-r--r--Hotline/macOS/News/NewsEditorView.swift19
-rw-r--r--Hotline/macOS/News/NewsItemView.swift8
-rw-r--r--Hotline/macOS/News/NewsView.swift12
3 files changed, 20 insertions, 19 deletions
diff --git a/Hotline/macOS/News/NewsEditorView.swift b/Hotline/macOS/News/NewsEditorView.swift
index f69c846..cc3e7d7 100644
--- a/Hotline/macOS/News/NewsEditorView.swift
+++ b/Hotline/macOS/News/NewsEditorView.swift
@@ -9,7 +9,7 @@ struct NewsEditorView: View {
@Environment(\.controlActiveState) private var controlActiveState
@Environment(\.colorScheme) private var colorScheme
@Environment(\.dismiss) private var dismiss
- @Environment(Hotline.self) private var model: Hotline
+ @Environment(HotlineState.self) private var model: HotlineState
let editorTitle: String
let isReply: Bool
@@ -24,15 +24,16 @@ struct NewsEditorView: View {
func sendArticle() async -> Bool {
sending = true
-
- let success = await model.postNewsArticle(title: title, body: text, at: path, parentID: parentID)
- if success {
- await model.getNewsList(at: path)
+
+ do {
+ try await model.postNewsArticle(title: title, body: text, at: path, parentID: parentID)
+ try? await model.getNewsList(at: path)
+ sending = false
+ return true
+ } catch {
+ sending = false
+ return false
}
-
- sending = false
-
- return success
}
var body: some View {
diff --git a/Hotline/macOS/News/NewsItemView.swift b/Hotline/macOS/News/NewsItemView.swift
index fc20e61..29c0e7d 100644
--- a/Hotline/macOS/News/NewsItemView.swift
+++ b/Hotline/macOS/News/NewsItemView.swift
@@ -1,7 +1,7 @@
import SwiftUI
struct NewsItemView: View {
- @Environment(Hotline.self) private var model: Hotline
+ @Environment(HotlineState.self) private var model: HotlineState
var news: NewsInfo
let depth: Int
@@ -132,9 +132,9 @@ struct NewsItemView: View {
guard news.expanded, news.type == .bundle || news.type == .category else {
return
}
-
+
Task {
- await model.getNewsList(at: news.path)
+ try? await model.getNewsList(at: news.path)
}
}
@@ -148,5 +148,5 @@ 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()))
+ .environment(HotlineState())
}
diff --git a/Hotline/macOS/News/NewsView.swift b/Hotline/macOS/News/NewsView.swift
index 91bf2fe..dfc5ab2 100644
--- a/Hotline/macOS/News/NewsView.swift
+++ b/Hotline/macOS/News/NewsView.swift
@@ -3,7 +3,7 @@ import MarkdownUI
import SplitView
struct NewsView: View {
- @Environment(Hotline.self) private var model: Hotline
+ @Environment(HotlineState.self) private var model: HotlineState
@Environment(\.openWindow) private var openWindow
@Environment(\.colorScheme) private var colorScheme
@@ -64,7 +64,7 @@ struct NewsView: View {
.task {
if !model.newsLoaded {
loading = true
- await model.getNewsList()
+ try? await model.getNewsList()
loading = false
}
}
@@ -123,13 +123,13 @@ struct NewsView: View {
loading = true
if let selectionPath = selection?.path {
Task {
- await model.getNewsList(at: selectionPath)
+ try? await model.getNewsList(at: selectionPath)
loading = false
}
}
else {
Task {
- await model.getNewsList()
+ try? await model.getNewsList()
loading = false
}
}
@@ -179,7 +179,7 @@ struct NewsView: View {
if let articleFlavor = article.articleFlavors?.first,
let articleID = article.articleID {
Task {
- if let articleText = await self.model.getNewsArticle(id: articleID, at: article.path, flavor: articleFlavor) {
+ if let articleText = try? await self.model.getNewsArticle(id: articleID, at: article.path, flavor: articleFlavor) {
self.articleText = articleText
}
}
@@ -293,5 +293,5 @@ struct NewsView: View {
#Preview {
NewsView()
- .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient()))
+ .environment(HotlineState())
}