diff --git a/Planet/Entities/PlanetStore.swift b/Planet/Entities/PlanetStore.swift index f61378cf..f9d93a15 100644 --- a/Planet/Entities/PlanetStore.swift +++ b/Planet/Entities/PlanetStore.swift @@ -98,6 +98,7 @@ enum PlanetDetailViewType: Hashable, Equatable { if let followingArticle = selectedArticle as? FollowingArticleModel { followingArticle.read = Date() try? followingArticle.save() + PlanetStore.shared.updateTotalUnreadCount() } } } @@ -166,6 +167,8 @@ enum PlanetDetailViewType: Hashable, Equatable { @Published var alertTitle: String = "" @Published var alertMessage: String = "" + @Published var totalUnreadCount: Int = 0 + nonisolated static let app: PlanetAppShell = (Bundle.main.executableURL?.lastPathComponent == "Croptop") ? .lite : .planet init() { @@ -249,6 +252,7 @@ enum PlanetDetailViewType: Hashable, Equatable { followingPlanets = Array(followingAllPlanets[followingPlanetPartition...]) loadFollowingPlanetsOrder() logger.info("Loaded \(self.followingPlanets.count) following planets") + updateTotalUnreadCount() } func publishMyPlanets() { @@ -266,6 +270,10 @@ enum PlanetDetailViewType: Hashable, Equatable { } } + func updateTotalUnreadCount() { + totalUnreadCount = followingPlanets.reduce(0) { $0 + $1.articles.filter { $0.read == nil }.count } + } + private let myPlanetsOrderKey = "myPlanetsOrder" func moveMyPlanets(fromOffsets source: IndexSet, toOffset destination: Int) { diff --git a/Planet/Views/Sidebar/PlanetSidebarView.swift b/Planet/Views/Sidebar/PlanetSidebarView.swift index 8309f4f6..bd71a159 100644 --- a/Planet/Views/Sidebar/PlanetSidebarView.swift +++ b/Planet/Views/Sidebar/PlanetSidebarView.swift @@ -45,6 +45,7 @@ struct PlanetSidebarView: View { .font(.body) .foregroundColor(.primary) } + .badge(planetStore.totalUnreadCount) .tag(PlanetDetailViewType.unread) HStack(spacing: 4) { diff --git a/Planet/versioning.xcconfig b/Planet/versioning.xcconfig index fc499a2a..4a1659dd 100644 --- a/Planet/versioning.xcconfig +++ b/Planet/versioning.xcconfig @@ -1 +1 @@ -CURRENT_PROJECT_VERSION = 2136 +CURRENT_PROJECT_VERSION = 2137