mirror of
https://github.com/mastodon/mastodon-ios.git
synced 2025-01-19 12:10:31 +01:00
Implement UserView follow button on SearchResultsViewController (IOS-140)
This commit is contained in:
parent
e2a05cd747
commit
1816c7ce1a
@ -28,7 +28,7 @@ extension SearchHistorySection {
|
||||
let userCellRegister = UICollectionView.CellRegistration<SearchHistoryUserCollectionViewCell, ManagedObjectRecord<MastodonUser>> { cell, indexPath, item in
|
||||
context.managedObjectContext.performAndWait {
|
||||
guard let user = item.object(in: context.managedObjectContext) else { return }
|
||||
cell.configure(viewModel: .init(value: user))
|
||||
cell.configure(viewModel: .init(value: user), delegate: configuration.searchHistorySectionHeaderCollectionReusableViewDelegate)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,8 +9,9 @@ import os.log
|
||||
import UIKit
|
||||
import MastodonAsset
|
||||
import MastodonLocalization
|
||||
import MastodonUI
|
||||
|
||||
protocol SearchHistorySectionHeaderCollectionReusableViewDelegate: AnyObject {
|
||||
protocol SearchHistorySectionHeaderCollectionReusableViewDelegate: AnyObject, UserViewDelegate {
|
||||
func searchHistorySectionHeaderCollectionReusableView(_ searchHistorySectionHeaderCollectionReusableView: SearchHistorySectionHeaderCollectionReusableView, clearButtonDidPressed button: UIButton)
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@
|
||||
|
||||
import Foundation
|
||||
import CoreDataStack
|
||||
import MastodonUI
|
||||
|
||||
extension SearchHistoryUserCollectionViewCell {
|
||||
final class ViewModel {
|
||||
@ -20,8 +21,9 @@ extension SearchHistoryUserCollectionViewCell {
|
||||
|
||||
extension SearchHistoryUserCollectionViewCell {
|
||||
func configure(
|
||||
viewModel: ViewModel
|
||||
viewModel: ViewModel,
|
||||
delegate: UserViewDelegate?
|
||||
) {
|
||||
userView.configure(user: viewModel.value, delegate: nil)
|
||||
userView.configure(user: viewModel.value, delegate: delegate)
|
||||
}
|
||||
}
|
||||
|
@ -10,6 +10,7 @@ import UIKit
|
||||
import Combine
|
||||
import CoreDataStack
|
||||
import MastodonCore
|
||||
import MastodonUI
|
||||
|
||||
final class SearchHistoryViewController: UIViewController, NeedsDependency {
|
||||
|
||||
@ -123,4 +124,15 @@ extension SearchHistoryViewController: SearchHistorySectionHeaderCollectionReusa
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func userView(_ view: UserView, didTapButtonWith state: UserView.ButtonState, for user: MastodonUser) {
|
||||
Task {
|
||||
try await DataSourceFacade.responseToUserViewButtonAction(
|
||||
dependency: self,
|
||||
user: user.asRecord,
|
||||
buttonState: state
|
||||
)
|
||||
collectionView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,7 @@
|
||||
import os.log
|
||||
import UIKit
|
||||
import Combine
|
||||
import CoreDataStack
|
||||
import MastodonCore
|
||||
import MastodonUI
|
||||
|
||||
@ -55,7 +56,8 @@ extension SearchResultViewController {
|
||||
// tableView.prefetchDataSource = self
|
||||
viewModel.setupDiffableDataSource(
|
||||
tableView: tableView,
|
||||
statusTableViewCellDelegate: self
|
||||
statusTableViewCellDelegate: self,
|
||||
userTableViewCellDelegate: self
|
||||
)
|
||||
|
||||
// setup batch fetch
|
||||
@ -255,3 +257,17 @@ extension SearchResultViewController: UITableViewDelegate, AutoGenerateTableView
|
||||
|
||||
// MARK: - StatusTableViewCellDelegate
|
||||
extension SearchResultViewController: StatusTableViewCellDelegate { }
|
||||
|
||||
// MARK: - UserTableViewCellDelegate
|
||||
extension SearchResultViewController: UserTableViewCellDelegate {
|
||||
func userView(_ view: UserView, didTapButtonWith state: UserView.ButtonState, for user: MastodonUser) {
|
||||
Task {
|
||||
try await DataSourceFacade.responseToUserViewButtonAction(
|
||||
dependency: self,
|
||||
user: user.asRecord,
|
||||
buttonState: state
|
||||
)
|
||||
tableView.reloadData()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,14 +12,16 @@ extension SearchResultViewModel {
|
||||
|
||||
func setupDiffableDataSource(
|
||||
tableView: UITableView,
|
||||
statusTableViewCellDelegate: StatusTableViewCellDelegate
|
||||
statusTableViewCellDelegate: StatusTableViewCellDelegate,
|
||||
userTableViewCellDelegate: UserTableViewCellDelegate
|
||||
) {
|
||||
diffableDataSource = SearchResultSection.tableViewDiffableDataSource(
|
||||
tableView: tableView,
|
||||
context: context,
|
||||
configuration: .init(
|
||||
authContext: authContext,
|
||||
statusViewTableViewCellDelegate: statusTableViewCellDelegate
|
||||
statusViewTableViewCellDelegate: statusTableViewCellDelegate,
|
||||
userTableViewCellDelegate: userTableViewCellDelegate
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -19,13 +19,7 @@ final class UserTableViewCell: UITableViewCell {
|
||||
|
||||
weak var delegate: UserTableViewCellDelegate?
|
||||
|
||||
let userView: UserView = {
|
||||
let view = UserView()
|
||||
[UserView.ButtonState.follow, UserView.ButtonState.unfollow, UserView.ButtonState.blocked].randomElement().map {
|
||||
view.setButtonState($0)
|
||||
}
|
||||
return view
|
||||
}()
|
||||
let userView = UserView()
|
||||
|
||||
let separatorLine = UIView.separatorLine
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user