diff --git a/Multiplatform/Shared/Article/ArticleToolbarModifier.swift b/Multiplatform/Shared/Article/ArticleToolbarModifier.swift index 7e3700527..afcff96aa 100644 --- a/Multiplatform/Shared/Article/ArticleToolbarModifier.swift +++ b/Multiplatform/Shared/Article/ArticleToolbarModifier.swift @@ -19,29 +19,32 @@ struct ArticleToolbarModifier: ViewModifier { ToolbarItem(placement: .navigation) { HStack(spacing: 20) { - Button(action: { - }, label: { + Button { + } label: { AppAssets.prevArticleImage .font(.title3) - }).help("Previouse Unread") - Button(action: { - }, label: { - AppAssets.nextArticleImage - .font(.title3) - }).help("Next Unread") + } + .help("Previouse Unread") + Button { + } label: { + AppAssets.nextArticleImage.font(.title3) + } + .help("Next Unread") } } ToolbarItem(placement: .bottomBar) { - Button(action: { sceneModel.toggleReadStatusForSelectedArticles() }, label: { - if sceneModel.readButtonState == .on { + Button { + sceneModel.toggleReadStatusForSelectedArticles() + } label: { + if sceneModel.readButtonState == true { AppAssets.readClosedImage } else { AppAssets.readOpenImage } - }) - .disabled(sceneModel.readButtonState == nil ? true : false) - .help(sceneModel.readButtonState == .on ? "Mark as Unread" : "Mark as Read") + } + .disabled(sceneModel.readButtonState == nil) + .help(sceneModel.readButtonState ?? false ? "Mark as Unread" : "Mark as Read") } ToolbarItem(placement: .bottomBar) { @@ -49,15 +52,17 @@ struct ArticleToolbarModifier: ViewModifier { } ToolbarItem(placement: .bottomBar) { - Button(action: { sceneModel.toggleStarredStatusForSelectedArticles() }, label: { - if sceneModel.starButtonState == .on { + Button { + sceneModel.toggleStarredStatusForSelectedArticles() + } label: { + if sceneModel.starButtonState ?? false { AppAssets.starClosedImage } else { AppAssets.starOpenImage } - }) - .disabled(sceneModel.starButtonState == nil ? true : false) - .help(sceneModel.starButtonState == .on ? "Mark as Unstarred" : "Mark as Starred") + } + .disabled(sceneModel.starButtonState == nil) + .help(sceneModel.starButtonState ?? false ? "Mark as Unstarred" : "Mark as Starred") } ToolbarItem(placement: .bottomBar) { @@ -65,11 +70,12 @@ struct ArticleToolbarModifier: ViewModifier { } ToolbarItem(placement: .bottomBar) { - Button(action: { - }, label: { - AppAssets.nextUnreadArticleImage - .font(.title3) - }).help("Next Unread") + Button { + } label: { + AppAssets.nextUnreadArticleImage.font(.title3) + } + .disabled(sceneModel.nextUnreadButtonState == nil) + .help("Next Unread") } ToolbarItem(placement: .bottomBar) { @@ -77,11 +83,13 @@ struct ArticleToolbarModifier: ViewModifier { } ToolbarItem(placement: .bottomBar) { - Button(action: { - }, label: { + Button { + } label: { AppAssets.articleExtractorOff .font(.title3) - }).help("Reader View") + } + .disabled(sceneModel.extractorButtonState == nil) + .help("Reader View") } ToolbarItem(placement: .bottomBar) { @@ -89,11 +97,12 @@ struct ArticleToolbarModifier: ViewModifier { } ToolbarItem(placement: .bottomBar) { - Button(action: { - }, label: { - AppAssets.shareImage - .font(.title3) - }).help("Share") + Button { + } label: { + AppAssets.shareImage.font(.title3) + } + .disabled(sceneModel.shareButtonState == nil) + .help("Share") } #endif diff --git a/Multiplatform/Shared/SceneModel.swift b/Multiplatform/Shared/SceneModel.swift index 3900b7913..f3cfad46a 100644 --- a/Multiplatform/Shared/SceneModel.swift +++ b/Multiplatform/Shared/SceneModel.swift @@ -16,8 +16,13 @@ final class SceneModel: ObservableObject { @Published var refreshProgressState = RefreshProgressModel.State.none + @Published var markAllAsReadButtonState: Bool? + @Published var nextUnreadButtonState: Bool? @Published var readButtonState: Bool? @Published var starButtonState: Bool? + @Published var extractorButtonState: ArticleExtractorButtonState? + @Published var openInBrowserButtonState: Bool? + @Published var shareButtonState: Bool? private var refreshProgressModel: RefreshProgressModel? = nil private var articleIconSchemeHandler: ArticleIconSchemeHandler? = nil @@ -44,7 +49,7 @@ final class SceneModel: ObservableObject { NotificationCenter.default.addObserver(self, selector: #selector(statusesDidChange(_:)), name: .StatusesDidChange, object: nil) selectedArticlesCancellable = timelineModel.$selectedArticles.sink { [weak self] articles in - self?.updateArticleState(articles: articles) + self?.updateArticleButtonsState(articles: articles) } } @@ -107,13 +112,13 @@ private extension SceneModel { } let selectedArticleIDs = timelineModel.selectedArticles.map { $0.articleID } if !articleIDs.intersection(selectedArticleIDs).isEmpty { - updateArticleState(articles: timelineModel.selectedArticles) + updateArticleButtonsState(articles: timelineModel.selectedArticles) } } // MARK: Button State Updates - func updateArticleState(articles: [Article]) { + func updateArticleButtonsState(articles: [Article]) { guard !articles.isEmpty else { readButtonState = nil starButtonState = nil @@ -133,6 +138,14 @@ private extension SceneModel { } else { starButtonState = true } + + if articles.count == 1, articles.first?.preferredLink != nil { + openInBrowserButtonState = true + shareButtonState = true + } else { + openInBrowserButtonState = nil + shareButtonState = nil + } } } diff --git a/Multiplatform/Shared/SceneNavigationView.swift b/Multiplatform/Shared/SceneNavigationView.swift index d201bda1e..708d12e0d 100644 --- a/Multiplatform/Shared/SceneNavigationView.swift +++ b/Multiplatform/Shared/SceneNavigationView.swift @@ -76,63 +76,84 @@ struct SceneNavigationView: View { } } ToolbarItem { - Button(action: {}, label: { + Button { + } label: { AppAssets.refreshImage - }).help("Refresh").padding(.trailing, 40) + } + .help("Refresh").padding(.trailing, 40) } ToolbarItem { - Button(action: {}, label: { + Button { + } label: { AppAssets.markAllAsReadImagePDF .resizable() .scaledToFit() .frame(width: 20, height: 20, alignment: .center) - }).help("Mark All as Read") + } + .disabled(sceneModel.markAllAsReadButtonState == nil) + .help("Mark All as Read") } ToolbarItem { MacSearchField() .frame(width: 200) } ToolbarItem { - Button(action: {}, label: { + Button { + } label: { AppAssets.nextUnreadArticleImage - }).help("Go to Next Unread").padding(.trailing, 40) + } + .disabled(sceneModel.nextUnreadButtonState == nil) + .help("Go to Next Unread").padding(.trailing, 40) } ToolbarItem { - Button(action: { sceneModel.toggleReadStatusForSelectedArticles() }, label: { + Button { + sceneModel.toggleReadStatusForSelectedArticles() + } label: { if sceneModel.readButtonState ?? false { AppAssets.readClosedImage } else { AppAssets.readOpenImage } - }) - .disabled(sceneModel.readButtonState == nil ? true : false) + } + .disabled(sceneModel.readButtonState == nil) .help(sceneModel.readButtonState ?? false ? "Mark as Unread" : "Mark as Read") } ToolbarItem { - Button(action: { sceneModel.toggleStarredStatusForSelectedArticles() }, label: { + Button { + sceneModel.toggleStarredStatusForSelectedArticles() + } label: { if sceneModel.starButtonState ?? false { AppAssets.starClosedImage } else { AppAssets.starOpenImage } - }) - .disabled(sceneModel.starButtonState == nil ? true : false) + } + .disabled(sceneModel.starButtonState == nil) .help(sceneModel.starButtonState ?? false ? "Mark as Unstarred" : "Mark as Starred") } ToolbarItem { - Button(action: {}, label: { + Button { + } label: { AppAssets.articleExtractorOff - }).help("Show Reader View") + } + .disabled(sceneModel.extractorButtonState == nil) + .help("Show Reader View") } ToolbarItem { - Button(action: {}, label: { + Button { + } label: { AppAssets.openInBrowserImage - }).help("Open in Browser") + } + .disabled(sceneModel.openInBrowserButtonState == nil) + .help("Open in Browser") } ToolbarItem { - Button(action: {}, label: { + Button { + } label: { AppAssets.shareImage - }).help("Share") + } + .disabled(sceneModel.shareButtonState == nil) + .help("Share") } #endif } diff --git a/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift b/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift index 6ca5f83d7..0c1236d28 100644 --- a/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift +++ b/Multiplatform/Shared/Sidebar/SidebarToolbarModifier.swift @@ -20,26 +20,27 @@ struct SidebarToolbarModifier: ViewModifier { .toolbar { ToolbarItem(placement: .navigation) { - Button (action: { + Button { withAnimation { sidebarModel.isReadFiltered.toggle() } - }, label: { + } label: { if sidebarModel.isReadFiltered { AppAssets.filterActiveImage.font(.title3) } else { AppAssets.filterInactiveImage.font(.title3) } - }).help(sidebarModel.isReadFiltered ? "Show Read Feeds" : "Filter Read Feeds") + } + .help(sidebarModel.isReadFiltered ? "Show Read Feeds" : "Filter Read Feeds") } ToolbarItem(placement: .automatic) { - Button(action: { + Button { viewModel.sheetToShow = .settings - }, label: { - AppAssets.settingsImage - .font(.title3) - }).help("Settings") + } label: { + AppAssets.settingsImage.font(.title3) + } + .help("Settings") } ToolbarItem { @@ -55,12 +56,11 @@ struct SidebarToolbarModifier: ViewModifier { } ToolbarItem(placement: .automatic, content: { - Button(action: { + Button { viewModel.showActionSheet = true - }, label: { - AppAssets.addMenuImage - .font(.title3) - }) + } label: { + AppAssets.addMenuImage.font(.title3) + } .help("Add") .actionSheet(isPresented: $viewModel.showActionSheet) { ActionSheet(title: Text("Add"), buttons: [ diff --git a/Multiplatform/Shared/Timeline/TimelineToolbarModifier.swift b/Multiplatform/Shared/Timeline/TimelineToolbarModifier.swift index 0d75b3bdf..f00cd05de 100644 --- a/Multiplatform/Shared/Timeline/TimelineToolbarModifier.swift +++ b/Multiplatform/Shared/Timeline/TimelineToolbarModifier.swift @@ -17,27 +17,27 @@ struct TimelineToolbarModifier: ViewModifier { .toolbar { #if os(iOS) ToolbarItem(placement: .navigation) { - Button (action: { + Button { withAnimation { timelineModel.toggleReadFilter() } - }, label: { + } label: { if timelineModel.isReadFiltered ?? false { AppAssets.filterActiveImage.font(.title3) } else { AppAssets.filterInactiveImage.font(.title3) } - }) + } .hidden(timelineModel.isReadFiltered == nil) .help(timelineModel.isReadFiltered ?? false ? "Show Read Articles" : "Filter Read Articles") } ToolbarItem { - Button(action: { - }, label: { - AppAssets.markAllAsReadImage - .foregroundColor(.accentColor) - }).help("Mark All As Read") + Button { + } label: { + AppAssets.markAllAsReadImage //.foregroundColor(.accentColor) + } + .help("Mark All As Read") } ToolbarItem { @@ -53,11 +53,11 @@ struct TimelineToolbarModifier: ViewModifier { } ToolbarItem { - Button(action: { - }, label: { - AppAssets.nextUnreadArticleImage - .font(.title3) - }).help("Next Unread") + Button { + } label: { + AppAssets.nextUnreadArticleImage.font(.title3) + } + .help("Next Unread") } #endif