feat: Implement navigating followed tags
This commit is contained in:
parent
855d2cbacd
commit
ba26dd2076
|
@ -24,9 +24,11 @@ final class FollowedTagsTableViewCell: UITableViewCell {
|
|||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
hashtagView.removeFromSuperview()
|
||||
viewModel = nil
|
||||
hashtagView = HashtagTimelineHeaderView()
|
||||
hashtagView = nil
|
||||
super.prepareForReuse()
|
||||
setup()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -61,5 +61,17 @@ extension FollowedTagsViewController {
|
|||
view.addSubview(tableView)
|
||||
tableView.pinToParent()
|
||||
viewModel.setupTableView(tableView)
|
||||
|
||||
viewModel.presentHashtagTimeline
|
||||
.receive(on: DispatchQueue.main)
|
||||
.sink { [weak self] hashtagTimelineViewModel in
|
||||
guard let self = self else { return }
|
||||
_ = self.coordinator.present(
|
||||
scene: .hashtagTimeline(viewModel: hashtagTimelineViewModel),
|
||||
from: self,
|
||||
transition: .show
|
||||
)
|
||||
}
|
||||
.store(in: &disposeBag)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,9 @@ final class FollowedTagsViewModel: NSObject {
|
|||
let context: AppContext
|
||||
let authContext: AuthContext
|
||||
|
||||
// output
|
||||
let presentHashtagTimeline = PassthroughSubject<HashtagTimelineViewModel, Never>()
|
||||
|
||||
init(context: AppContext, authContext: AuthContext) {
|
||||
self.context = context
|
||||
self.authContext = authContext
|
||||
|
@ -115,6 +118,21 @@ extension FollowedTagsViewModel: UITableViewDataSource {
|
|||
|
||||
extension FollowedTagsViewModel: UITableViewDelegate {
|
||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||
logger.log(level: .debug, "\((#file as NSString).lastPathComponent, privacy: .public)[\(#line, privacy: .public)], \(#function, privacy: .public): \(indexPath)")
|
||||
tableView.deselectRow(at: indexPath, animated: true)
|
||||
|
||||
guard
|
||||
indexPath.section == 0,
|
||||
let object = fetchedResultsController.records[indexPath.row].object(in: context.managedObjectContext)
|
||||
else {
|
||||
return
|
||||
}
|
||||
|
||||
let hashtagTimelineViewModel = HashtagTimelineViewModel(
|
||||
context: self.context,
|
||||
authContext: self.authContext,
|
||||
hashtag: object.name
|
||||
)
|
||||
presentHashtagTimeline.send(hashtagTimelineViewModel)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,6 +31,7 @@ public final class FollowedTagsFetchedResultController: NSObject {
|
|||
self.fetchedResultsController = {
|
||||
let fetchRequest = Tag.sortedFetchRequest
|
||||
fetchRequest.predicate = Tag.predicate(domain: domain, following: true, by: user)
|
||||
fetchRequest.sortDescriptors = Tag.defaultSortDescriptors
|
||||
fetchRequest.returnsObjectsAsFaults = false
|
||||
fetchRequest.fetchBatchSize = 20
|
||||
let controller = NSFetchedResultsController(
|
||||
|
@ -74,17 +75,11 @@ public final class FollowedTagsFetchedResultController: NSObject {
|
|||
|
||||
// MARK: - NSFetchedResultsControllerDelegate
|
||||
extension FollowedTagsFetchedResultController: NSFetchedResultsControllerDelegate {
|
||||
public func controller(_ controller: NSFetchedResultsController<NSFetchRequestResult>, didChangeContentWith snapshot: NSDiffableDataSourceSnapshotReference) {
|
||||
public func controllerDidChangeContent(_ controller: NSFetchedResultsController<NSFetchRequestResult>) {
|
||||
os_log("%{public}s[%{public}ld], %{public}s", ((#file as NSString).lastPathComponent), #line, #function)
|
||||
|
||||
let objects = fetchedResultsController.fetchedObjects ?? []
|
||||
|
||||
let items: [NSManagedObjectID] = objects
|
||||
// .compactMap { object in
|
||||
// indexes.firstIndex(of: object.id).map { index in (index, object) }
|
||||
// }
|
||||
// .sorted { $0.0 < $1.0 }
|
||||
.map { $0.objectID }
|
||||
self._objectIDs.value = items
|
||||
self._objectIDs.value = objects.map { $0.objectID }
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue