From 4bf4c6d6c25381138917ba2f5e7b616b39cbbb07 Mon Sep 17 00:00:00 2001 From: Maurice Parker Date: Mon, 20 Jul 2020 09:40:56 -0500 Subject: [PATCH] Restore Mark All As Read in Feed context menu after making it performant --- .../Shared/Timeline/TimelineContextMenu.swift | 24 +++++++++---------- .../Shared/Timeline/TimelineModel.swift | 5 +--- 2 files changed, 12 insertions(+), 17 deletions(-) diff --git a/Multiplatform/Shared/Timeline/TimelineContextMenu.swift b/Multiplatform/Shared/Timeline/TimelineContextMenu.swift index 0c2994b7c..b32ae9309 100644 --- a/Multiplatform/Shared/Timeline/TimelineContextMenu.swift +++ b/Multiplatform/Shared/Timeline/TimelineContextMenu.swift @@ -81,19 +81,17 @@ struct TimelineContextMenu: View { } } -// This thing isn't lazily initialized and gets called excessively even for things like selecting an article - -// if let feed = timelineItem.article.webFeed, timelineModel.canMarkAllAsReadInFeed(feed) { -// Divider() -// Button { -// timelineModel.markAllAsReadInFeed(feed) -// } label: { -// Text("Mark All as Read in “\(feed.nameForDisplay)”") -// #if os(iOS) -// AppAssets.markAllAsReadImage -// #endif -// } -// } + if let feed = timelineItem.article.webFeed, timelineModel.canMarkAllAsReadInFeed(feed) { + Divider() + Button { + timelineModel.markAllAsReadInFeed(feed) + } label: { + Text("Mark All as Read in “\(feed.nameForDisplay)”") + #if os(iOS) + AppAssets.markAllAsReadImage + #endif + } + } if timelineModel.canOpenIndicatedArticleInBrowser(timelineItem.article) { Divider() diff --git a/Multiplatform/Shared/Timeline/TimelineModel.swift b/Multiplatform/Shared/Timeline/TimelineModel.swift index f9c102343..c13ee7298 100644 --- a/Multiplatform/Shared/Timeline/TimelineModel.swift +++ b/Multiplatform/Shared/Timeline/TimelineModel.swift @@ -238,10 +238,7 @@ class TimelineModel: ObservableObject, UndoableCommandRunner { } func canMarkAllAsReadInFeed(_ feed: Feed) -> Bool { - guard let articlesSet = try? feed.fetchArticles() else { - return false - } - return Array(articlesSet).canMarkAllAsRead() + return feed.unreadCount > 0 } func markAllAsReadInFeed(_ feed: Feed) {