Skip to content

Commit

Permalink
Show total unread count badge
Browse files Browse the repository at this point in the history
  • Loading branch information
livid committed Jul 19, 2024
1 parent ca5ba55 commit 55155fd
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions Planet/Entities/PlanetStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ enum PlanetDetailViewType: Hashable, Equatable {
if let followingArticle = selectedArticle as? FollowingArticleModel {
followingArticle.read = Date()
try? followingArticle.save()
PlanetStore.shared.updateTotalUnreadCount()
}
}
}
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -249,6 +252,7 @@ enum PlanetDetailViewType: Hashable, Equatable {
followingPlanets = Array(followingAllPlanets[followingPlanetPartition...])
loadFollowingPlanetsOrder()
logger.info("Loaded \(self.followingPlanets.count) following planets")
updateTotalUnreadCount()
}

func publishMyPlanets() {
Expand All @@ -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) {
Expand Down
1 change: 1 addition & 0 deletions Planet/Views/Sidebar/PlanetSidebarView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ struct PlanetSidebarView: View {
.font(.body)
.foregroundColor(.primary)
}
.badge(planetStore.totalUnreadCount)
.tag(PlanetDetailViewType.unread)

HStack(spacing: 4) {
Expand Down
2 changes: 1 addition & 1 deletion Planet/versioning.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CURRENT_PROJECT_VERSION = 2136
CURRENT_PROJECT_VERSION = 2137

0 comments on commit 55155fd

Please sign in to comment.