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 { extension NewStatusViewController: PHPickerViewControllerDelegate {
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) {
mediaSelections.send(results) mediaSelections.send(results)
@ -169,6 +173,7 @@ private extension NewStatusViewController {
stackView.isUserInteractionEnabled = false stackView.isUserInteractionEnabled = false
stackView.alpha = 0.5 stackView.alpha = 0.5
case .done: case .done:
NotificationCenter.default.post(.init(name: Self.newStatusPostedNotification))
dismiss() dismiss()
} }
} }

View file

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