Skip to content

Commit

Permalink
Update tag header button to filter feed
Browse files Browse the repository at this point in the history
  • Loading branch information
wargcm committed May 10, 2024
1 parent e6e066b commit 93f2856
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
2 changes: 2 additions & 0 deletions WordPress/Classes/ViewRelated/Reader/ReaderHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ extension NSNotification.Name {
static let ReaderUserBlockingWillBegin = NSNotification.Name(rawValue: "ReaderUserBlockingWillBegin")
// Sent when the user blocking request is complete
static let ReaderUserBlockingDidEnd = NSNotification.Name(rawValue: "ReaderUserBlockingDidEnd")
// Sent when the filter from a feed is updated
static let ReaderFilterUpdated = NSNotification.Name(rawValue: "ReaderFilterUpdated")
}

struct ReaderNotificationKeys {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ReaderTagCardCell: UITableViewCell {
}

@IBAction private func onTagButtonTapped(_ sender: Any) {
viewModel?.onTagButtonTapped()
viewModel?.onTagHeaderButtonTapped()
}

struct Constants {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ReaderTagCardCellViewModel: NSObject {
let slug: String
weak var viewDelegate: ReaderTagCardCellViewModelDelegate? = nil

private let tag: ReaderAbstractTopic
private let coreDataStack: CoreDataStackSwift
private weak var parentViewController: UIViewController?
private weak var collectionView: UICollectionView?
Expand Down Expand Up @@ -64,6 +65,7 @@ class ReaderTagCardCellViewModel: NSObject {
cellSize: @escaping @autoclosure () -> CGSize?) {
self.parentViewController = parent
self.slug = tag.slug
self.tag = tag
self.collectionView = collectionView
self.isLoggedIn = isLoggedIn
self.viewDelegate = viewDelegate
Expand Down Expand Up @@ -100,6 +102,12 @@ class ReaderTagCardCellViewModel: NSObject {
}
}

func onTagHeaderButtonTapped() {
NotificationCenter.default.post(name: .ReaderFilterUpdated,
object: nil,
userInfo: [ReaderNotificationKeys.topic: tag])
}

func onTagButtonTapped() {
let controller = ReaderStreamViewController.controllerWithTagSlug(slug)
parentViewController?.navigationController?.pushViewController(controller, animated: true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class ReaderTabView: UIView {

NotificationCenter.default.addObserver(self, selector: #selector(topicUnfollowed(_:)), name: .ReaderTopicUnfollowed, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(siteFollowed(_:)), name: .ReaderSiteFollowed, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(filterUpdated(_:)), name: .ReaderFilterUpdated, object: nil)
}

required init?(coder: NSCoder) {
Expand Down Expand Up @@ -215,6 +216,16 @@ private extension ReaderTabView {
viewModel.fetchReaderMenu()
}

@objc func filterUpdated(_ notification: Foundation.Notification) {
guard let userInfo = notification.userInfo,
let topic = userInfo[ReaderNotificationKeys.topic] as? ReaderTagTopic,
let filterProvider = viewModel.streamFilters.first(where: { $0.reuseIdentifier == FilterProvider.ReuseIdentifiers.tags }) else {
return
}
viewModel.setFilterContent(topic: topic)
viewModel.activeStreamFilter = (filterProvider.id, topic)
}

}

// MARK: - Appearance
Expand Down

0 comments on commit 93f2856

Please sign in to comment.