2021-11-01 12:54:07 +01:00
|
|
|
//
|
|
|
|
// UserSection.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by Cirno MainasuK on 2021-11-1.
|
|
|
|
//
|
|
|
|
|
|
|
|
import os.log
|
|
|
|
import UIKit
|
|
|
|
import CoreData
|
|
|
|
import CoreDataStack
|
|
|
|
import MetaTextKit
|
|
|
|
import MastodonMeta
|
|
|
|
|
|
|
|
enum UserSection: Hashable {
|
|
|
|
case main
|
|
|
|
}
|
|
|
|
|
|
|
|
extension UserSection {
|
|
|
|
|
|
|
|
static let logger = Logger(subsystem: "StatusSection", category: "logic")
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
struct Configuration {
|
|
|
|
weak var userTableViewCellDelegate: UserTableViewCellDelegate?
|
|
|
|
}
|
2021-11-01 12:54:07 +01:00
|
|
|
|
2022-01-27 14:23:39 +01:00
|
|
|
static func diffableDataSource(
|
|
|
|
tableView: UITableView,
|
|
|
|
context: AppContext,
|
|
|
|
configuration: Configuration
|
2021-11-01 12:54:07 +01:00
|
|
|
) -> UITableViewDiffableDataSource<UserSection, UserItem> {
|
2022-01-27 14:23:39 +01:00
|
|
|
tableView.register(UserTableViewCell.self, forCellReuseIdentifier: String(describing: UserTableViewCell.self))
|
|
|
|
|
|
|
|
return UITableViewDiffableDataSource(tableView: tableView) { tableView, indexPath, item -> UITableViewCell? in
|
2021-11-01 12:54:07 +01:00
|
|
|
switch item {
|
2022-01-27 14:23:39 +01:00
|
|
|
case .user(let record):
|
2021-11-01 12:54:07 +01:00
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as! UserTableViewCell
|
2022-01-27 14:23:39 +01:00
|
|
|
context.managedObjectContext.performAndWait {
|
|
|
|
guard let user = record.object(in: context.managedObjectContext) else { return }
|
|
|
|
configure(
|
|
|
|
tableView: tableView,
|
|
|
|
cell: cell,
|
|
|
|
viewModel: .init(value: .user(user)),
|
|
|
|
configuration: configuration
|
|
|
|
)
|
2021-11-01 12:54:07 +01:00
|
|
|
}
|
|
|
|
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
|
|
|
|
} // end switch
|
|
|
|
} // end UITableViewDiffableDataSource
|
|
|
|
} // end static func tableViewDiffableDataSource { … }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
extension UserSection {
|
|
|
|
|
|
|
|
static func configure(
|
2022-01-27 14:23:39 +01:00
|
|
|
tableView: UITableView,
|
2021-11-01 12:54:07 +01:00
|
|
|
cell: UserTableViewCell,
|
2022-01-27 14:23:39 +01:00
|
|
|
viewModel: UserTableViewCell.ViewModel,
|
|
|
|
configuration: Configuration
|
2021-11-01 12:54:07 +01:00
|
|
|
) {
|
2022-01-27 14:23:39 +01:00
|
|
|
|
|
|
|
cell.configure(
|
|
|
|
tableView: tableView,
|
|
|
|
viewModel: viewModel,
|
|
|
|
delegate: configuration.userTableViewCellDelegate
|
|
|
|
)
|
2021-11-01 12:54:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|