2022-01-27 14:23:39 +01:00
|
|
|
//
|
|
|
|
// TimelineMiddleLoaderTableViewCell+ViewModel.swift
|
|
|
|
// Mastodon
|
|
|
|
//
|
|
|
|
// Created by MainasuK on 2022-1-17.
|
|
|
|
//
|
|
|
|
|
|
|
|
import UIKit
|
|
|
|
import Combine
|
|
|
|
import CoreDataStack
|
|
|
|
|
|
|
|
extension TimelineMiddleLoaderTableViewCell {
|
2022-10-10 13:14:52 +02:00
|
|
|
public class ViewModel {
|
2022-01-27 14:23:39 +01:00
|
|
|
var disposeBag = Set<AnyCancellable>()
|
|
|
|
|
|
|
|
@Published var isFetching = false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
extension TimelineMiddleLoaderTableViewCell.ViewModel {
|
2022-10-10 13:14:52 +02:00
|
|
|
public func bind(cell: TimelineMiddleLoaderTableViewCell) {
|
2022-01-27 14:23:39 +01:00
|
|
|
$isFetching
|
|
|
|
.sink { isFetching in
|
|
|
|
if isFetching {
|
|
|
|
cell.startAnimating()
|
|
|
|
} else {
|
|
|
|
cell.stopAnimating()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extension TimelineMiddleLoaderTableViewCell {
|
2022-10-10 13:14:52 +02:00
|
|
|
public func configure(
|
2022-01-27 14:23:39 +01:00
|
|
|
feed: Feed,
|
|
|
|
delegate: TimelineMiddleLoaderTableViewCellDelegate?
|
|
|
|
) {
|
|
|
|
feed.publisher(for: \.isLoadingMore)
|
|
|
|
.sink { [weak self] isLoadingMore in
|
|
|
|
guard let self = self else { return }
|
|
|
|
self.viewModel.isFetching = isLoadingMore
|
|
|
|
}
|
|
|
|
.store(in: &disposeBag)
|
|
|
|
|
|
|
|
self.delegate = delegate
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|