Compare commits
No commits in common. "bcae60316b4fcadfe6805e3b401b35c68d30f121" and "f5704e561b8cb15b4e4afae6296c921b3442230f" have entirely different histories.
bcae60316b
...
f5704e561b
|
@ -17,7 +17,7 @@ class EditListAccountsViewController: UIViewController, CollectionViewController
|
|||
|
||||
private var state = State.unloaded
|
||||
|
||||
private(set) var shouldReloadListTimeline = false
|
||||
private(set) var changedAccounts = false
|
||||
|
||||
private var dataSource: UICollectionViewDiffableDataSource<Section, Item>!
|
||||
var collectionView: UICollectionView! { view as? UICollectionView }
|
||||
|
@ -186,7 +186,7 @@ class EditListAccountsViewController: UIViewController, CollectionViewController
|
|||
|
||||
@MainActor
|
||||
private func loadAccounts() async {
|
||||
guard state == .unloaded || state == .loaded else { return }
|
||||
guard state == .unloaded else { return }
|
||||
|
||||
state = .loading
|
||||
|
||||
|
@ -278,7 +278,7 @@ class EditListAccountsViewController: UIViewController, CollectionViewController
|
|||
}
|
||||
|
||||
private func addAccount(id: String) async {
|
||||
shouldReloadListTimeline = true
|
||||
changedAccounts = true
|
||||
do {
|
||||
let req = List.add(list.id, accounts: [id])
|
||||
_ = try await mastodonController.run(req)
|
||||
|
@ -294,19 +294,11 @@ class EditListAccountsViewController: UIViewController, CollectionViewController
|
|||
}
|
||||
|
||||
private func removeAccount(id: String) async {
|
||||
shouldReloadListTimeline = true
|
||||
changedAccounts = true
|
||||
do {
|
||||
let request = List.remove(list.id, accounts: [id])
|
||||
_ = try await mastodonController.run(request)
|
||||
|
||||
var snapshot = dataSource.snapshot()
|
||||
if snapshot.itemIdentifiers.contains(.account(id: id)) {
|
||||
snapshot.deleteItems([.account(id: id)])
|
||||
await MainActor.run {
|
||||
dataSource.apply(snapshot)
|
||||
}
|
||||
}
|
||||
|
||||
await self.loadAccounts()
|
||||
} catch {
|
||||
let config = ToastConfiguration(from: error, with: "Error Removing Account", in: self) { [unowned self] toast in
|
||||
toast.dismissToast(animated: true)
|
||||
|
@ -317,7 +309,6 @@ class EditListAccountsViewController: UIViewController, CollectionViewController
|
|||
}
|
||||
|
||||
private func setReplyPolicy(_ replyPolicy: List.ReplyPolicy) {
|
||||
shouldReloadListTimeline = true
|
||||
Task {
|
||||
let service = EditListSettingsService(list: list, mastodonController: mastodonController, present: { self.present($0, animated: true) })
|
||||
await service.run(replyPolicy: replyPolicy)
|
||||
|
|
|
@ -16,8 +16,6 @@ class ListTimelineViewController: TimelineViewController {
|
|||
|
||||
var presentEditOnAppear = false
|
||||
|
||||
private var noContentView: UIStackView!
|
||||
|
||||
private var listRenamedCancellable: AnyCancellable?
|
||||
|
||||
init(for list: List, mastodonController: MastodonController) {
|
||||
|
@ -55,39 +53,6 @@ class ListTimelineViewController: TimelineViewController {
|
|||
}
|
||||
}
|
||||
|
||||
private func createNoContentView() {
|
||||
let title = UILabel()
|
||||
title.textColor = .secondaryLabel
|
||||
title.font = .preferredFont(forTextStyle: .title1).withTraits(.traitBold)!
|
||||
title.adjustsFontForContentSizeCategory = true
|
||||
title.text = "No Posts"
|
||||
|
||||
let subtitle = UILabel()
|
||||
subtitle.textColor = .secondaryLabel
|
||||
subtitle.font = .preferredFont(forTextStyle: .body)
|
||||
subtitle.adjustsFontForContentSizeCategory = true
|
||||
subtitle.numberOfLines = 0
|
||||
subtitle.textAlignment = .center
|
||||
subtitle.text = "This list doesn't currently have any posts. Edit it to add accounts if necessary."
|
||||
|
||||
noContentView = UIStackView(arrangedSubviews: [
|
||||
title,
|
||||
subtitle,
|
||||
])
|
||||
noContentView.axis = .vertical
|
||||
noContentView.spacing = 8
|
||||
noContentView.alignment = .center
|
||||
noContentView.isAccessibilityElement = true
|
||||
noContentView.accessibilityLabel = subtitle.text
|
||||
noContentView.translatesAutoresizingMaskIntoConstraints = false
|
||||
view.addSubview(noContentView)
|
||||
NSLayoutConstraint.activate([
|
||||
noContentView.centerYAnchor.constraint(equalTo: view.centerYAnchor),
|
||||
noContentView.leadingAnchor.constraint(equalToSystemSpacingAfter: view.safeAreaLayoutGuide.leadingAnchor, multiplier: 1),
|
||||
view.safeAreaLayoutGuide.trailingAnchor.constraint(equalToSystemSpacingAfter: noContentView.trailingAnchor, multiplier: 1),
|
||||
])
|
||||
}
|
||||
|
||||
private func listChanged() {
|
||||
title = list.title
|
||||
}
|
||||
|
@ -96,23 +61,10 @@ class ListTimelineViewController: TimelineViewController {
|
|||
let editListAccountsController = EditListAccountsViewController(list: list, mastodonController: mastodonController)
|
||||
editListAccountsController.navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(editListDoneButtonPressed))
|
||||
let navController = UINavigationController(rootViewController: editListAccountsController)
|
||||
navController.sheetPresentationController?.delegate = self
|
||||
present(navController, animated: animated)
|
||||
}
|
||||
|
||||
private func reloadIfNecessary(editViewController: EditListAccountsViewController) {
|
||||
guard editViewController.shouldReloadListTimeline else {
|
||||
return
|
||||
}
|
||||
noContentView?.removeFromSuperview()
|
||||
noContentView = nil
|
||||
Task {
|
||||
applyInitialSnapshot()
|
||||
await controller.loadInitial()
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Interaction
|
||||
// MARK: - Interaction
|
||||
|
||||
@objc func editListButtonPressed() {
|
||||
presentEdit(animated: true)
|
||||
|
@ -123,28 +75,12 @@ class ListTimelineViewController: TimelineViewController {
|
|||
|
||||
dismiss(animated: true)
|
||||
|
||||
if let presented {
|
||||
self.reloadIfNecessary(editViewController: presented)
|
||||
if presented?.changedAccounts == true {
|
||||
Task {
|
||||
applyInitialSnapshot()
|
||||
await controller.loadInitial()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: TimelineLikeControllerDelegate
|
||||
|
||||
override func handleReplaceAllItems(_ timelineItems: [String]) async {
|
||||
if timelineItems.isEmpty {
|
||||
createNoContentView()
|
||||
}
|
||||
await super.handleReplaceAllItems(timelineItems)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension ListTimelineViewController: UISheetPresentationControllerDelegate {
|
||||
func presentationControllerWillDismiss(_ presentationController: UIPresentationController) {
|
||||
guard let nav = presentationController.presentedViewController as? UINavigationController,
|
||||
let edit = nav.viewControllers.first as? EditListAccountsViewController else {
|
||||
return
|
||||
}
|
||||
reloadIfNecessary(editViewController: edit)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1016,18 +1016,6 @@ class TimelineViewController: UIViewController, TimelineLikeCollectionViewContro
|
|||
}
|
||||
self.showToast(configuration: config, animated: true)
|
||||
}
|
||||
|
||||
// this is copied from the TimelineLikeCollectionViewController implementation because it needs to be overridable by ListTimelineViewController
|
||||
func handleReplaceAllItems(_ timelineItems: [String]) async {
|
||||
var snapshot = dataSource.snapshot()
|
||||
if snapshot.sectionIdentifiers.contains(.entries) {
|
||||
snapshot.deleteSections([.entries])
|
||||
}
|
||||
snapshot.appendSections([.entries])
|
||||
snapshot.appendItems(timelineItems.map { .fromTimelineItem($0) }, toSection: .entries)
|
||||
await apply(snapshot, animatingDifferences: false)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
extension TimelineViewController {
|
||||
|
|
Loading…
Reference in New Issue