mastodon-ios/Mastodon/Diffable/User/UserSection.swift

64 lines
2.5 KiB
Swift

//
// UserSection.swift
// Mastodon
//
// Created by Cirno MainasuK on 2021-11-1.
//
import UIKit
import CoreData
import CoreDataStack
import MastodonCore
import MastodonUI
import MastodonMeta
import MetaTextKit
import Combine
enum UserSection: Hashable {
case main
}
extension UserSection {
static func diffableDataSource(
tableView: UITableView,
context: AppContext,
authContext: AuthContext,
userTableViewCellDelegate: UserTableViewCellDelegate?
) -> UITableViewDiffableDataSource<UserSection, UserItem> {
tableView.register(UserTableViewCell.self, forCellReuseIdentifier: String(describing: UserTableViewCell.self))
tableView.register(TimelineBottomLoaderTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self))
tableView.register(TimelineFooterTableViewCell.self, forCellReuseIdentifier: String(describing: TimelineFooterTableViewCell.self))
return UITableViewDiffableDataSource(tableView: tableView) {
tableView,
indexPath,
item -> UITableViewCell? in
switch item {
case .account(let account, let relationship):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as! UserTableViewCell
guard let me = authContext.mastodonAuthenticationBox.authentication.account() else { return cell }
cell.userView.setButtonState(.loading)
cell.configure(
me: me,
tableView: tableView,
account: account,
relationship: relationship,
delegate: userTableViewCellDelegate
)
return cell
case .bottomLoader:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as! TimelineBottomLoaderTableViewCell
cell.startAnimating()
return cell
case .bottomHeader(let text):
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineFooterTableViewCell.self), for: indexPath) as! TimelineFooterTableViewCell
cell.messageLabel.text = text
return cell
}
}
}
}