2021-04-02 10:24:00 +02:00
|
|
|
//
|
|
|
|
// SearchResultSection.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by sxiaojian on 2021/4/6.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import MastodonSDK
|
|
|
|
import UIKit
|
|
|
|
|
|
|
|
enum SearchResultSection: Equatable, Hashable {
|
|
|
|
case account
|
|
|
|
case hashTag
|
2021-04-06 09:25:04 +02:00
|
|
|
case bottomLoader
|
2021-04-02 10:24:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
extension SearchResultSection {
|
|
|
|
static func tableViewDiffableDataSource(
|
|
|
|
for tableView: UITableView
|
|
|
|
) -> UITableViewDiffableDataSource<SearchResultSection, SearchResultItem> {
|
|
|
|
UITableViewDiffableDataSource(tableView: tableView) { (tableView, indexPath, result) -> UITableViewCell? in
|
|
|
|
switch result {
|
|
|
|
case .account(let account):
|
2021-04-06 09:25:04 +02:00
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchingTableViewCell.self), for: indexPath) as! SearchingTableViewCell
|
2021-04-02 10:24:00 +02:00
|
|
|
cell.config(with: account)
|
2021-04-06 09:25:04 +02:00
|
|
|
return cell
|
2021-04-02 10:24:00 +02:00
|
|
|
case .hashTag(let tag):
|
2021-04-06 09:25:04 +02:00
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchingTableViewCell.self), for: indexPath) as! SearchingTableViewCell
|
2021-04-02 10:24:00 +02:00
|
|
|
cell.config(with: tag)
|
2021-04-06 09:25:04 +02:00
|
|
|
return cell
|
|
|
|
case .bottomLoader:
|
|
|
|
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: SearchBottomLoader.self)) as! SearchBottomLoader
|
|
|
|
cell.startAnimating()
|
|
|
|
return cell
|
2021-04-02 10:24:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|