forked from shadowfacts/Tusker
Change sidebar Discover section to be collapsible
This commit is contained in:
parent
916c6fba0d
commit
cb2bb215d3
|
@ -148,21 +148,24 @@ class MainSidebarViewController: UIViewController {
|
|||
], toSection: .compose)
|
||||
if mastodonController.instanceFeatures.instanceType.isMastodon,
|
||||
!Preferences.shared.hideDiscover {
|
||||
addDiscoverSection(to: &snapshot)
|
||||
snapshot.insertSections([.discover], afterSection: .compose)
|
||||
}
|
||||
dataSource.apply(snapshot, animatingDifferences: false)
|
||||
|
||||
applyDiscoverSectionSnapshot()
|
||||
reloadLists()
|
||||
reloadSavedHashtags()
|
||||
reloadSavedInstances()
|
||||
}
|
||||
|
||||
private func addDiscoverSection(to snapshot: inout NSDiffableDataSourceSnapshot<Section, Item>) {
|
||||
snapshot.insertSections([.discover], afterSection: .compose)
|
||||
snapshot.appendItems([
|
||||
private func applyDiscoverSectionSnapshot() {
|
||||
var discoverSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
|
||||
discoverSnapshot.append([.discoverHeader])
|
||||
discoverSnapshot.append([
|
||||
.trendingTags,
|
||||
.profileDirectory,
|
||||
], toSection: .discover)
|
||||
], to: .discoverHeader)
|
||||
dataSource.apply(discoverSnapshot, to: .discover)
|
||||
}
|
||||
|
||||
private func ownInstanceLoaded(_ instance: Instance) {
|
||||
|
@ -244,12 +247,14 @@ class MainSidebarViewController: UIViewController {
|
|||
let hide = Preferences.shared.hideDiscover
|
||||
if hasSection && hide {
|
||||
snapshot.deleteSections([.discover])
|
||||
dataSource.apply(snapshot)
|
||||
} else if !hasSection && !hide {
|
||||
addDiscoverSection(to: &snapshot)
|
||||
snapshot.insertSections([.discover], afterSection: .compose)
|
||||
dataSource.apply(snapshot)
|
||||
applyDiscoverSectionSnapshot()
|
||||
} else {
|
||||
return
|
||||
}
|
||||
dataSource.apply(snapshot)
|
||||
}
|
||||
|
||||
// todo: deduplicate with ExploreViewController
|
||||
|
@ -330,7 +335,7 @@ extension MainSidebarViewController {
|
|||
enum Item: Hashable {
|
||||
case tab(MainTabBarViewController.Tab)
|
||||
case search, bookmarks
|
||||
case trendingTags, profileDirectory
|
||||
case discoverHeader, trendingTags, profileDirectory
|
||||
case listsHeader, list(List), addList
|
||||
case savedHashtagsHeader, savedHashtag(Hashtag), addSavedHashtag
|
||||
case savedInstancesHeader, savedInstance(URL), addSavedInstance
|
||||
|
@ -343,6 +348,8 @@ extension MainSidebarViewController {
|
|||
return "Search"
|
||||
case .bookmarks:
|
||||
return "Bookmarks"
|
||||
case .discoverHeader:
|
||||
return "Discover"
|
||||
case .trendingTags:
|
||||
return "Trending Hashtags"
|
||||
case .profileDirectory:
|
||||
|
@ -386,7 +393,7 @@ extension MainSidebarViewController {
|
|||
return "number"
|
||||
case .savedInstance(_):
|
||||
return "globe"
|
||||
case .listsHeader, .savedHashtagsHeader, .savedInstancesHeader:
|
||||
case .discoverHeader, .listsHeader, .savedHashtagsHeader, .savedInstancesHeader:
|
||||
return nil
|
||||
case .addList, .addSavedHashtag, .addSavedInstance:
|
||||
return "plus"
|
||||
|
@ -395,7 +402,7 @@ extension MainSidebarViewController {
|
|||
|
||||
var hasChildren: Bool {
|
||||
switch self {
|
||||
case .listsHeader, .savedHashtagsHeader, .savedInstancesHeader:
|
||||
case .discoverHeader, .listsHeader, .savedHashtagsHeader, .savedInstancesHeader:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
|
|
|
@ -215,7 +215,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
|
|||
let explore = exploreNav.viewControllers.first as! ExploreViewController
|
||||
explore.searchControllerStatusOnAppearance = false
|
||||
|
||||
case .listsHeader, .addList, .savedHashtagsHeader, .addSavedHashtag, .savedInstancesHeader, .addSavedInstance:
|
||||
case .discoverHeader, .listsHeader, .addList, .savedHashtagsHeader, .addSavedHashtag, .savedInstancesHeader, .addSavedInstance:
|
||||
// These items are not selectable in the sidebar collection view, so this code is unreachable.
|
||||
fatalError("unreachable")
|
||||
}
|
||||
|
@ -345,7 +345,7 @@ fileprivate extension MainSidebarViewController.Item {
|
|||
return HashtagTimelineViewController(for: hashtag, mastodonController: mastodonController)
|
||||
case let .savedInstance(url):
|
||||
return InstanceTimelineViewController(for: url, parentMastodonController: mastodonController)
|
||||
case .listsHeader, .addList, .savedHashtagsHeader, .addSavedHashtag, .savedInstancesHeader, .addSavedInstance:
|
||||
case .discoverHeader, .listsHeader, .addList, .savedHashtagsHeader, .addSavedHashtag, .savedInstancesHeader, .addSavedInstance:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue