Return to previous item when the selected list/hashtag/instance is removed from the sidebar
This commit is contained in:
parent
a2b3fc0628
commit
2f0acad866
|
@ -209,6 +209,12 @@ class MainSidebarViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
private func reloadLists(_ lists: [List]) {
|
private func reloadLists(_ lists: [List]) {
|
||||||
|
if let selectedItem,
|
||||||
|
case .list(let list) = selectedItem,
|
||||||
|
!lists.contains(where: { $0.id == list.id }) {
|
||||||
|
returnToPreviousItem()
|
||||||
|
}
|
||||||
|
|
||||||
var exploreSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
|
var exploreSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
|
||||||
exploreSnapshot.append([.listsHeader])
|
exploreSnapshot.append([.listsHeader])
|
||||||
exploreSnapshot.expand([.listsHeader])
|
exploreSnapshot.expand([.listsHeader])
|
||||||
|
@ -240,24 +246,36 @@ class MainSidebarViewController: UIViewController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func reloadSavedHashtags() {
|
@objc private func reloadSavedHashtags() {
|
||||||
var hashtagsSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
|
|
||||||
hashtagsSnapshot.append([.savedHashtagsHeader])
|
|
||||||
hashtagsSnapshot.expand([.savedHashtagsHeader])
|
|
||||||
let hashtags = fetchSavedHashtags().map {
|
let hashtags = fetchSavedHashtags().map {
|
||||||
Item.savedHashtag(Hashtag(name: $0.name, url: $0.url))
|
Item.savedHashtag(Hashtag(name: $0.name, url: $0.url))
|
||||||
}
|
}
|
||||||
|
if let selectedItem,
|
||||||
|
case .savedHashtag(_) = selectedItem,
|
||||||
|
!hashtags.contains(selectedItem) {
|
||||||
|
returnToPreviousItem()
|
||||||
|
}
|
||||||
|
|
||||||
|
var hashtagsSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
|
||||||
|
hashtagsSnapshot.append([.savedHashtagsHeader])
|
||||||
|
hashtagsSnapshot.expand([.savedHashtagsHeader])
|
||||||
hashtagsSnapshot.append(hashtags, to: .savedHashtagsHeader)
|
hashtagsSnapshot.append(hashtags, to: .savedHashtagsHeader)
|
||||||
hashtagsSnapshot.append([.addSavedHashtag], to: .savedHashtagsHeader)
|
hashtagsSnapshot.append([.addSavedHashtag], to: .savedHashtagsHeader)
|
||||||
self.dataSource.apply(hashtagsSnapshot, to: .savedHashtags)
|
self.dataSource.apply(hashtagsSnapshot, to: .savedHashtags)
|
||||||
}
|
}
|
||||||
|
|
||||||
@objc private func reloadSavedInstances() {
|
@objc private func reloadSavedInstances() {
|
||||||
var instancesSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
|
|
||||||
instancesSnapshot.append([.savedInstancesHeader])
|
|
||||||
instancesSnapshot.expand([.savedInstancesHeader])
|
|
||||||
let instances = fetchSavedInstances().map {
|
let instances = fetchSavedInstances().map {
|
||||||
Item.savedInstance($0.url)
|
Item.savedInstance($0.url)
|
||||||
}
|
}
|
||||||
|
if let selectedItem,
|
||||||
|
case .savedInstance(_) = selectedItem,
|
||||||
|
!instances.contains(selectedItem) {
|
||||||
|
returnToPreviousItem()
|
||||||
|
}
|
||||||
|
|
||||||
|
var instancesSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
|
||||||
|
instancesSnapshot.append([.savedInstancesHeader])
|
||||||
|
instancesSnapshot.expand([.savedInstancesHeader])
|
||||||
instancesSnapshot.append(instances, to: .savedInstancesHeader)
|
instancesSnapshot.append(instances, to: .savedInstancesHeader)
|
||||||
instancesSnapshot.append([.addSavedInstance], to: .savedInstancesHeader)
|
instancesSnapshot.append([.addSavedInstance], to: .savedInstancesHeader)
|
||||||
self.dataSource.apply(instancesSnapshot, to: .savedInstances)
|
self.dataSource.apply(instancesSnapshot, to: .savedInstances)
|
||||||
|
@ -279,6 +297,13 @@ class MainSidebarViewController: UIViewController {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func returnToPreviousItem() {
|
||||||
|
let item = previouslySelectedItem ?? .tab(.timelines)
|
||||||
|
previouslySelectedItem = nil
|
||||||
|
select(item: item, animated: true)
|
||||||
|
sidebarDelegate?.sidebar(self, didSelectItem: item)
|
||||||
|
}
|
||||||
|
|
||||||
private func showAddList() {
|
private func showAddList() {
|
||||||
let service = CreateListService(mastodonController: mastodonController, present: { self.present($0, animated: true
|
let service = CreateListService(mastodonController: mastodonController, present: { self.present($0, animated: true
|
||||||
) }) { list in
|
) }) { list in
|
||||||
|
|
Loading…
Reference in New Issue