-
-
Notifications
You must be signed in to change notification settings - Fork 297
Expand file tree
/
Copy pathUserSection.swift
More file actions
62 lines (55 loc) · 2.54 KB
/
UserSection.swift
File metadata and controls
62 lines (55 loc) · 2.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
//
// 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,
authenticationBox: MastodonAuthenticationBox,
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):
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: UserTableViewCell.self), for: indexPath) as? UserTableViewCell else { fatalError("WTF?! Wrong cell.") }
guard let me = authenticationBox.cachedAccount else { return cell }
cell.userView.setButtonState(.loading)
cell.configure(
me: me,
tableView: tableView,
account: account,
relationship: relationship,
delegate: userTableViewCellDelegate
)
return cell
case .bottomLoader:
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineBottomLoaderTableViewCell.self), for: indexPath) as? TimelineBottomLoaderTableViewCell else { fatalError("WTF?! Wrong cell.") }
cell.startAnimating()
return cell
case .bottomHeader(let text):
guard let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: TimelineFooterTableViewCell.self), for: indexPath) as? TimelineFooterTableViewCell else { fatalError("WTF?! Wrong cell.") }
cell.messageLabel.text = text
return cell
}
}
}
}