mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-14 04:21:01 +00:00
Show announcement count
This commit is contained in:
parent
07dad77fd7
commit
cb97e21cd2
5 changed files with 24 additions and 7 deletions
|
@ -609,7 +609,7 @@ public extension ContentDatabase {
|
|||
ValueObservation.tracking(Announcement.fetchCount)
|
||||
.removeDuplicates()
|
||||
.publisher(in: databaseWriter)
|
||||
.combineLatest(ValueObservation.tracking(Announcement.fetchCount)
|
||||
.combineLatest(ValueObservation.tracking(Announcement.filter(Announcement.Columns.read == false).fetchCount)
|
||||
.removeDuplicates()
|
||||
.publisher(in: databaseWriter))
|
||||
.map { (total: $0, unread: $1) }
|
||||
|
|
|
@ -141,6 +141,8 @@ class TableViewController: UITableViewController {
|
|||
if let loadMoreView = cell.contentView as? LoadMoreView {
|
||||
visibleLoadMoreViews.insert(loadMoreView)
|
||||
}
|
||||
|
||||
(cell.contentView as? AnnouncementView)?.dismissIfUnread()
|
||||
}
|
||||
|
||||
override func tableView(_ tableView: UITableView,
|
||||
|
|
|
@ -41,7 +41,7 @@ final class TimelinesViewController: UIPageViewController {
|
|||
image: UIImage(systemName: "newspaper"),
|
||||
selectedImage: nil)
|
||||
|
||||
announcementsButton.primaryAction = UIAction(
|
||||
let announcementsAction = UIAction(
|
||||
title: NSLocalizedString("main-navigation.announcements", comment: ""),
|
||||
image: UIImage(systemName: "megaphone")) { [weak self] _ in
|
||||
guard let self = self else { return }
|
||||
|
@ -52,8 +52,21 @@ final class TimelinesViewController: UIPageViewController {
|
|||
self.navigationController?.pushViewController(announcementsViewController, animated: true)
|
||||
}
|
||||
|
||||
announcementsButton.primaryAction = announcementsAction
|
||||
|
||||
viewModel.$announcementCount
|
||||
.sink { [weak self] in
|
||||
if $0.unread > 0 {
|
||||
announcementsAction.image = UIImage(systemName: "\($0.unread).circle.fill")
|
||||
?? UIImage(systemName: "megaphone.fill")
|
||||
self?.announcementsButton.primaryAction = announcementsAction
|
||||
self?.announcementsButton.tintColor = .systemRed
|
||||
} else {
|
||||
announcementsAction.image = UIImage(systemName: "megaphone")
|
||||
self?.announcementsButton.primaryAction = announcementsAction
|
||||
self?.announcementsButton.tintColor = nil
|
||||
}
|
||||
|
||||
self?.navigationItem.rightBarButtonItem = $0.total > 0 ? self?.announcementsButton : nil
|
||||
}
|
||||
.store(in: &cancellables)
|
||||
|
|
|
@ -33,7 +33,9 @@ public extension AnnouncementViewModel {
|
|||
.eraseToAnyPublisher())
|
||||
}
|
||||
|
||||
func dismiss() {
|
||||
func dismissIfUnread() {
|
||||
guard !announcement.read else { return }
|
||||
|
||||
eventsSubject.send(
|
||||
announcementService.dismiss()
|
||||
.map { _ in .ignorableOutput }
|
||||
|
|
|
@ -47,6 +47,10 @@ extension AnnouncementView {
|
|||
static func estimatedHeight(width: CGFloat, announcement: Announcement) -> CGFloat {
|
||||
UITableView.automaticDimension
|
||||
}
|
||||
|
||||
func dismissIfUnread() {
|
||||
announcementConfiguration.viewModel.dismissIfUnread()
|
||||
}
|
||||
}
|
||||
|
||||
extension AnnouncementView: UIContentView {
|
||||
|
@ -167,9 +171,5 @@ private extension AnnouncementView {
|
|||
if snapshot.itemIdentifiers != dataSource.snapshot().itemIdentifiers {
|
||||
dataSource.apply(snapshot, animatingDifferences: false) { viewModel.reload() }
|
||||
}
|
||||
|
||||
if !viewModel.announcement.read {
|
||||
viewModel.dismiss()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue