diff --git a/Tusker/Screens/Main/MainSidebarViewController.swift b/Tusker/Screens/Main/MainSidebarViewController.swift index 251ad9dc4e..403fc11b72 100644 --- a/Tusker/Screens/Main/MainSidebarViewController.swift +++ b/Tusker/Screens/Main/MainSidebarViewController.swift @@ -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) { - snapshot.insertSections([.discover], afterSection: .compose) - snapshot.appendItems([ + private func applyDiscoverSectionSnapshot() { + var discoverSnapshot = NSDiffableDataSourceSectionSnapshot() + 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 diff --git a/Tusker/Screens/Main/MainSplitViewController.swift b/Tusker/Screens/Main/MainSplitViewController.swift index c0261bd613..e80439b772 100644 --- a/Tusker/Screens/Main/MainSplitViewController.swift +++ b/Tusker/Screens/Main/MainSplitViewController.swift @@ -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 } }