diff options
| author | Dustin Mierau <dustin@mierau.me> | 2024-05-14 13:35:26 -0700 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2024-05-14 13:35:26 -0700 |
| commit | 87e979fb48da4a46e64544cea3e7b7d5fc32caa1 (patch) | |
| tree | 4c10cdba5a88544543bf45ae454f643decf1358c /Hotline/macOS/NewsView.swift | |
| parent | e9fcf8c3b14e77479a6fb471bb51cd82a008147c (diff) | |
Newsgroup posting now works. Added reload button to news. More work on server and user icons.
Diffstat (limited to 'Hotline/macOS/NewsView.swift')
| -rw-r--r-- | Hotline/macOS/NewsView.swift | 65 |
1 files changed, 52 insertions, 13 deletions
diff --git a/Hotline/macOS/NewsView.swift b/Hotline/macOS/NewsView.swift index 8df741f..ed5d969 100644 --- a/Hotline/macOS/NewsView.swift +++ b/Hotline/macOS/NewsView.swift @@ -12,6 +12,8 @@ struct NewsView: View { @State private var splitHidden = SideHolder(.bottom) @State private var splitFraction = FractionHolder.usingUserDefaults(0.25, key: "News Split Fraction") @State private var editorOpen: Bool = false + @State private var replyOpen: Bool = false + @State private var loading: Bool = true var body: some View { Group { @@ -63,45 +65,82 @@ struct NewsView: View { } .task { if !model.newsLoaded { - let _ = await model.getNewsList() + await model.getNewsList() + loading = false } } } } .sheet(isPresented: $editorOpen) { - print("Sheet dismissed!") } content: { - NewsEditorView() - } - .toolbar { - ToolbarItem(placement: .primaryAction) { - Button { - - } label: { - Image(systemName: "trash") + if let selection = selection { + switch selection.type { + case .article, .category: + NewsEditorView(editorTitle: selection.path.last ?? "New Post", isReply: false, path: selection.path, parentID: 0) + default: + EmptyView() } } - + else { + EmptyView() + } + } + .sheet(isPresented: $replyOpen) { + } content: { + if let selection = selection, selection.type == .article { + NewsEditorView(editorTitle: "Reply to \(selection.articleUsername ?? "Post")", isReply: true, path: selection.path, parentID: UInt32(selection.articleID!), title: selection.name.replyToString()) + } + else { + EmptyView() + } + } + .toolbar { ToolbarItem(placement: .primaryAction) { Button { if selection?.type == .category || selection?.type == .article { editorOpen = true -// openWindow(id: "news-editor", value: NewsArticle(parentID: nil, path: selection.path, title: "", body: "")) } } label: { Image(systemName: "square.and.pencil") } + .help("New Post") .disabled(selection?.type != .category && selection?.type != .article) } ToolbarItem(placement: .primaryAction) { Button { - + if selection?.type == .article { + replyOpen = true + } } label: { Image(systemName: "arrowshape.turn.up.left") } + .help("Reply to Post") .disabled(selection?.type != .article) } + + ToolbarItem(placement: .primaryAction) { + Button { + if let selectionPath = selection?.path { + Task { + loading = true + await model.getNewsList(at: selectionPath) + loading = false + } + } + else { + Task { + loading = true + await model.getNewsList() + loading = false + } + } + } label: { + Image(systemName: "arrow.clockwise") + } + .help("Reload Newsgroup") + .disabled(loading) + } } } |