Compare commits
No commits in common. "814f64b3e2e06acec26e35fef474f557c686d8f0" and "522e7830e5d9dfb7fcf10842b5586df7ad1d2af8" have entirely different histories.
814f64b3e2
...
522e7830e5
|
@ -9,14 +9,14 @@
|
|||
import UIKit
|
||||
import Pachyderm
|
||||
|
||||
class AddSavedHashtagViewController: UIViewController, CollectionViewController {
|
||||
class AddSavedHashtagViewController: UIViewController {
|
||||
|
||||
weak var mastodonController: MastodonController!
|
||||
|
||||
var resultsController: SearchResultsViewController!
|
||||
var searchController: UISearchController!
|
||||
|
||||
private(set) var collectionView: UICollectionView!
|
||||
private var collectionView: UICollectionView!
|
||||
private var dataSource: UICollectionViewDiffableDataSource<Section, Item>!
|
||||
|
||||
init(mastodonController: MastodonController) {
|
||||
|
@ -91,12 +91,6 @@ class AddSavedHashtagViewController: UIViewController, CollectionViewController
|
|||
override func viewWillAppear(_ animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
if searchController.isActive {
|
||||
resultsController.clearSelectionOnAppear(animated: animated)
|
||||
}
|
||||
|
||||
clearSelectionOnAppear(animated: animated)
|
||||
|
||||
let request = Client.getTrendingHashtags(limit: 10)
|
||||
mastodonController.run(request) { (response) in
|
||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||
|
@ -114,63 +108,7 @@ class AddSavedHashtagViewController: UIViewController, CollectionViewController
|
|||
}
|
||||
|
||||
private func selectHashtag(_ hashtag: Hashtag) {
|
||||
let vc = HashtagTimelineViewController(for: hashtag, mastodonController: mastodonController)
|
||||
vc.loadViewIfNeeded()
|
||||
|
||||
let mastodonController = mastodonController!
|
||||
let context = mastodonController.persistentContainer.viewContext
|
||||
let existingSaved = try? context.fetch(SavedHashtag.fetchRequest(name: hashtag.name, account: mastodonController.accountInfo!)).first
|
||||
let saveItem = UIBarButtonItem()
|
||||
func updateSaveItem(saved: Bool) {
|
||||
saveItem.title = saved ? "Unsave Hashag" : "Save Hashtag"
|
||||
saveItem.image = UIImage(systemName: saved ? "minus" : "plus")
|
||||
}
|
||||
saveItem.primaryAction = UIAction(handler: { [unowned self] _ in
|
||||
// re-fetch this in case the button's been tapped before and the captured var would be out of date
|
||||
let existingSaved = try? context.fetch(SavedHashtag.fetchRequest(name: hashtag.name, account: mastodonController.accountInfo!)).first
|
||||
if let existingSaved {
|
||||
context.delete(existingSaved)
|
||||
} else {
|
||||
_ = SavedHashtag(hashtag: hashtag, account: mastodonController.accountInfo!, context: context)
|
||||
}
|
||||
mastodonController.persistentContainer.save(context: context)
|
||||
updateSaveItem(saved: existingSaved == nil)
|
||||
if existingSaved == nil {
|
||||
self.presentingViewController?.dismiss(animated: true)
|
||||
}
|
||||
})
|
||||
// setting primaryAction replace's the bar button's title/image with the action, so do this after
|
||||
updateSaveItem(saved: existingSaved != nil)
|
||||
|
||||
vc.navigationItem.rightBarButtonItems = [
|
||||
saveItem,
|
||||
]
|
||||
|
||||
if mastodonController.instanceFeatures.canFollowHashtags {
|
||||
let existingFollowed = mastodonController.followedHashtags.first(where: { $0.name.lowercased() == hashtag.name })
|
||||
let followItem = UIBarButtonItem()
|
||||
func updateFollowItem(followed: Bool) {
|
||||
followItem.title = followed ? "Unfollow Hashtag" : "Follow Hashtag"
|
||||
followItem.image = UIImage(systemName: "person.badge.\(followed ? "minus" : "plus")")
|
||||
}
|
||||
followItem.primaryAction = UIAction(handler: { [unowned self] _ in
|
||||
Task {
|
||||
let success = await ToggleFollowHashtagService(hashtagName: hashtag.name, presenter: self).toggleFollow()
|
||||
if success {
|
||||
let followed = mastodonController.followedHashtags.contains(where: { $0.name.lowercased() == hashtag.name })
|
||||
updateFollowItem(followed: followed)
|
||||
if followed {
|
||||
self.presentingViewController?.dismiss(animated: true)
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
updateFollowItem(followed: existingFollowed != nil)
|
||||
|
||||
vc.navigationItem.rightBarButtonItems!.append(followItem)
|
||||
}
|
||||
|
||||
show(vc, sender: self)
|
||||
show(HashtagTimelineViewController(for: hashtag, mastodonController: mastodonController), sender: nil)
|
||||
}
|
||||
|
||||
// MARK: - Interaction
|
||||
|
@ -206,7 +144,3 @@ extension AddSavedHashtagViewController: SearchResultsViewControllerDelegate {
|
|||
selectHashtag(hashtag)
|
||||
}
|
||||
}
|
||||
|
||||
extension AddSavedHashtagViewController: TuskerNavigationDelegate {
|
||||
var apiController: MastodonController! { mastodonController }
|
||||
}
|
||||
|
|
|
@ -96,7 +96,7 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate, Collect
|
|||
// so we manually propagate this down to the results controller
|
||||
// so that it can deselect on appear
|
||||
if searchController.isActive {
|
||||
resultsController.clearSelectionOnAppear(animated: animated)
|
||||
resultsController.viewWillAppear(animated)
|
||||
}
|
||||
|
||||
clearSelectionOnAppear(animated: animated)
|
||||
|
@ -308,7 +308,6 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate, Collect
|
|||
actions.append(UIContextualAction(style: .destructive, title: "Unsave", handler: { _, _, completion in
|
||||
context.delete(existing)
|
||||
try! context.save()
|
||||
completion(true)
|
||||
}))
|
||||
}
|
||||
if mastodonController.instanceFeatures.canFollowHashtags,
|
||||
|
|
Loading…
Reference in New Issue