Fix creating list on iPad overwriting previous item navigation stack

This commit is contained in:
Shadowfacts 2022-11-30 16:33:28 -05:00
parent 948eff1f7e
commit b515664db3
1 changed files with 3 additions and 31 deletions

View File

@ -213,23 +213,7 @@ class MainSidebarViewController: UIViewController {
exploreSnapshot.expand([.listsHeader])
exploreSnapshot.append(lists.map { .list($0) }, to: .listsHeader)
exploreSnapshot.append([.addList], to: .listsHeader)
var selectedItem: Item?
if let selectedIndexPath = collectionView.indexPathsForSelectedItems?.first,
let item = dataSource.itemIdentifier(for: selectedIndexPath) {
if case .list(let list) = item,
let newList = lists.first(where: { $0.id == list.id }) {
selectedItem = .list(newList)
} else {
selectedItem = item
}
}
self.dataSource.apply(exploreSnapshot, to: .lists) {
if let selectedItem,
let indexPath = self.dataSource.indexPath(for: selectedItem) {
self.collectionView.selectItem(at: indexPath, animated: false, scrollPosition: .centeredVertically)
}
}
self.dataSource.apply(exploreSnapshot, to: .lists)
}
@MainActor
@ -255,8 +239,6 @@ class MainSidebarViewController: UIViewController {
}
@objc private func reloadSavedHashtags() {
let selected = collectionView.indexPathsForSelectedItems?.first
var hashtagsSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
hashtagsSnapshot.append([.savedHashtagsHeader])
hashtagsSnapshot.expand([.savedHashtagsHeader])
@ -265,16 +247,10 @@ class MainSidebarViewController: UIViewController {
}
hashtagsSnapshot.append(hashtags, to: .savedHashtagsHeader)
hashtagsSnapshot.append([.addSavedHashtag], to: .savedHashtagsHeader)
self.dataSource.apply(hashtagsSnapshot, to: .savedHashtags, animatingDifferences: false) {
if let selected = selected {
self.collectionView.selectItem(at: selected, animated: false, scrollPosition: .centeredVertically)
}
}
self.dataSource.apply(hashtagsSnapshot, to: .savedHashtags)
}
@objc private func reloadSavedInstances() {
let selected = collectionView.indexPathsForSelectedItems?.first
var instancesSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
instancesSnapshot.append([.savedInstancesHeader])
instancesSnapshot.expand([.savedInstancesHeader])
@ -283,11 +259,7 @@ class MainSidebarViewController: UIViewController {
}
instancesSnapshot.append(instances, to: .savedInstancesHeader)
instancesSnapshot.append([.addSavedInstance], to: .savedInstancesHeader)
self.dataSource.apply(instancesSnapshot, to: .savedInstances, animatingDifferences: false) {
if let selected = selected {
self.collectionView.selectItem(at: selected, animated: false, scrollPosition: .centeredVertically)
}
}
self.dataSource.apply(instancesSnapshot, to: .savedInstances)
}
@objc private func preferencesChanged() {