From 87e979fb48da4a46e64544cea3e7b7d5fc32caa1 Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Tue, 14 May 2024 13:35:26 -0700 Subject: Newsgroup posting now works. Added reload button to news. More work on server and user icons. --- Hotline/macOS/NewsView.swift | 65 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 52 insertions(+), 13 deletions(-) (limited to 'Hotline/macOS/NewsView.swift') 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) + } } } -- cgit