chore: add navigation to hashtagViewController
This commit is contained in:
parent
0dab9acd91
commit
2331867758
|
@ -86,6 +86,6 @@ extension SearchViewController: UITableViewDelegate {
|
||||||
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
||||||
guard let diffableDataSource = viewModel.searchResultDiffableDataSource else { return }
|
guard let diffableDataSource = viewModel.searchResultDiffableDataSource else { return }
|
||||||
guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return }
|
guard let item = diffableDataSource.itemIdentifier(for: indexPath) else { return }
|
||||||
viewModel.saveItemToCoreData(item: item)
|
viewModel.searchResultItemDidSelected(item: item, from: self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ final class SearchViewController: UIViewController, NeedsDependency {
|
||||||
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
weak var coordinator: SceneCoordinator! { willSet { precondition(!isViewLoaded) } }
|
||||||
|
|
||||||
var disposeBag = Set<AnyCancellable>()
|
var disposeBag = Set<AnyCancellable>()
|
||||||
private(set) lazy var viewModel = SearchViewModel(context: context)
|
private(set) lazy var viewModel = SearchViewModel(context: context, coordinator: coordinator)
|
||||||
|
|
||||||
let searchBar: UISearchBar = {
|
let searchBar: UISearchBar = {
|
||||||
let searchBar = UISearchBar()
|
let searchBar = UISearchBar()
|
||||||
|
|
|
@ -19,6 +19,7 @@ final class SearchViewModel: NSObject {
|
||||||
|
|
||||||
// input
|
// input
|
||||||
let context: AppContext
|
let context: AppContext
|
||||||
|
weak var coordinator: SceneCoordinator!
|
||||||
|
|
||||||
// output
|
// output
|
||||||
let searchText = CurrentValueSubject<String, Never>("")
|
let searchText = CurrentValueSubject<String, Never>("")
|
||||||
|
@ -51,7 +52,8 @@ final class SearchViewModel: NSObject {
|
||||||
|
|
||||||
lazy var loadOldestStateMachinePublisher = CurrentValueSubject<LoadOldestState?, Never>(nil)
|
lazy var loadOldestStateMachinePublisher = CurrentValueSubject<LoadOldestState?, Never>(nil)
|
||||||
|
|
||||||
init(context: AppContext) {
|
init(context: AppContext,coordinator: SceneCoordinator) {
|
||||||
|
self.coordinator = coordinator
|
||||||
self.context = context
|
self.context = context
|
||||||
super.init()
|
super.init()
|
||||||
|
|
||||||
|
@ -233,7 +235,7 @@ final class SearchViewModel: NSObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func saveItemToCoreData(item: SearchResultItem) {
|
func searchResultItemDidSelected(item: SearchResultItem,from: UIViewController) {
|
||||||
let searchHistories = self.fetchSearchHistory()
|
let searchHistories = self.fetchSearchHistory()
|
||||||
_ = context.managedObjectContext.performChanges { [weak self] in
|
_ = context.managedObjectContext.performChanges { [weak self] in
|
||||||
guard let self = self else { return }
|
guard let self = self else { return }
|
||||||
|
@ -285,6 +287,8 @@ final class SearchViewModel: NSObject {
|
||||||
} else {
|
} else {
|
||||||
SearchHistory.insert(into: self.context.managedObjectContext, hashtag: tagInCoreData)
|
SearchHistory.insert(into: self.context.managedObjectContext, hashtag: tagInCoreData)
|
||||||
}
|
}
|
||||||
|
let viewModel = HashtagTimelineViewModel(context: self.context, hashtag: tagInCoreData.name)
|
||||||
|
self.coordinator.present(scene: .hashtagTimeline(viewModel: viewModel), from: from, transition: .show)
|
||||||
case .accountObjectID(let accountObjectID):
|
case .accountObjectID(let accountObjectID):
|
||||||
if let searchHistories = searchHistories {
|
if let searchHistories = searchHistories {
|
||||||
let history = searchHistories.first { history -> Bool in
|
let history = searchHistories.first { history -> Bool in
|
||||||
|
@ -305,6 +309,9 @@ final class SearchViewModel: NSObject {
|
||||||
history.update(updatedAt: Date())
|
history.update(updatedAt: Date())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
let tagInCoreData = self.context.managedObjectContext.object(with: hashtagObjectID) as! Tag
|
||||||
|
let viewModel = HashtagTimelineViewModel(context: self.context, hashtag: tagInCoreData.name)
|
||||||
|
self.coordinator.present(scene: .hashtagTimeline(viewModel: viewModel), from: from, transition: .show)
|
||||||
default:
|
default:
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue