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