Refresh modifications

This commit is contained in:
Justin Mazzocchi 2021-01-28 18:41:41 -08:00
parent 08d4e43ddb
commit 6800055ced
No known key found for this signature in database
GPG key ID: E223E6937AAFB01C
2 changed files with 17 additions and 3 deletions

View file

@ -96,6 +96,10 @@ final class NewStatusViewController: UIViewController {
}
}
extension NewStatusViewController {
static let newStatusPostedNotification = Notification.Name("com.metabolist.metatext.new-status-posted-notification")
}
extension NewStatusViewController: PHPickerViewControllerDelegate {
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
mediaSelections.send(results)
@ -169,6 +173,7 @@ private extension NewStatusViewController {
stackView.isUserInteractionEnabled = false
stackView.alpha = 0.5
case .done:
NotificationCenter.default.post(.init(name: Self.newStatusPostedNotification))
dismiss()
}
}

View file

@ -56,7 +56,7 @@ class TableViewController: UITableViewController {
refreshControl = UIRefreshControl()
refreshControl?.addAction(
UIAction { [weak self] _ in
self?.viewModel.request(maxId: nil, minId: nil, search: nil) },
self?.refreshIfAble() },
for: .valueChanged)
}
@ -69,12 +69,14 @@ class TableViewController: UITableViewController {
])
setupViewModelBindings()
viewModel.request(maxId: nil, minId: nil, search: nil)
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
viewModel.request(maxId: nil, minId: nil, search: nil)
refreshIfAble()
}
override func scrollViewDidScroll(_ scrollView: UIScrollView) {
@ -289,7 +291,8 @@ private extension TableViewController {
.store(in: &cancellables)
NotificationCenter.default.publisher(for: UIScene.willEnterForegroundNotification)
.sink { [weak self] _ in self?.viewModel.request(maxId: nil, minId: nil, search: nil) }
.merge(with: NotificationCenter.default.publisher(for: NewStatusViewController.newStatusPostedNotification))
.sink { [weak self] _ in self?.refreshIfAble() }
.store(in: &cancellables)
}
@ -492,5 +495,11 @@ private extension TableViewController {
present(activityViewController, animated: true, completion: nil)
}
func refreshIfAble() {
if viewModel.canRefresh {
viewModel.request(maxId: nil, minId: nil, search: nil)
}
}
}
// swiftlint:enable file_length