Add Trending Hashtags to sidebar

This commit is contained in:
Shadowfacts 2021-02-07 10:45:36 -05:00
parent 9f0883d0cb
commit 13cdb5d8c7
2 changed files with 16 additions and 3 deletions

View File

@ -32,7 +32,7 @@ class MainSidebarViewController: UIViewController {
}
var exploreTabItems: [Item] {
var items: [Item] = [.search, .bookmarks]
var items: [Item] = [.search, .bookmarks, .trendingTags]
let snapshot = dataSource.snapshot()
for case let .list(list) in snapshot.itemIdentifiers(inSection: .lists) {
items.append(.list(list))
@ -141,6 +141,9 @@ class MainSidebarViewController: UIViewController {
snapshot.appendItems([
.tab(.compose)
], toSection: .compose)
snapshot.appendItems([
.trendingTags,
], toSection: .discover)
dataSource.apply(snapshot, animatingDifferences: false)
reloadLists()
@ -272,6 +275,7 @@ extension MainSidebarViewController {
enum Section: Int, Hashable, CaseIterable {
case tabs
case compose
case discover
case lists
case savedHashtags
case savedInstances
@ -279,6 +283,7 @@ extension MainSidebarViewController {
enum Item: Hashable {
case tab(MainTabBarViewController.Tab)
case search, bookmarks
case trendingTags
case listsHeader, list(List), addList
case savedHashtagsHeader, savedHashtag(Hashtag), addSavedHashtag
case savedInstancesHeader, savedInstance(URL), addSavedInstance
@ -291,6 +296,8 @@ extension MainSidebarViewController {
return "Search"
case .bookmarks:
return "Bookmarks"
case .trendingTags:
return "Trending Hashtags"
case .listsHeader:
return "Lists"
case let .list(list):
@ -320,6 +327,8 @@ extension MainSidebarViewController {
return "magnifyingglass"
case .bookmarks:
return "bookmark"
case .trendingTags:
return "arrow.up.arrow.down"
case .list(_):
return "list.bullet"
case .savedHashtag(_):

View File

@ -203,7 +203,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
tabBarViewController.select(tab: .explore)
case .bookmarks, .list(_), .savedHashtag(_), .savedInstance(_):
case .bookmarks, .trendingTags, .list(_), .savedHashtag(_), .savedInstance(_):
tabBarViewController.select(tab: .explore)
// Make sure the Explore VC doesn't show it's search bar when it appears, in case the user was previously
// in compact mode and performing a search.
@ -277,6 +277,8 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
exploreItem = .savedHashtag(hashtagVC.hashtag)
} else if let instanceVC = tabNavigationStack[1] as? InstanceTimelineViewController {
exploreItem = .savedInstance(instanceVC.instanceURL)
} else if tabNavigationStack[1] is TrendingHashtagsViewController {
exploreItem = .trendingTags
}
transferNavigationStack(from: tabNavController, to: exploreItem!, skipFirst: 1, prepend: toPrepend)
@ -328,13 +330,15 @@ fileprivate extension MainSidebarViewController.Item {
return SearchViewController(mastodonController: mastodonController)
case .bookmarks:
return BookmarksTableViewController(mastodonController: mastodonController)
case .trendingTags:
return TrendingHashtagsViewController(mastodonController: mastodonController)
case let .list(list):
return ListTimelineViewController(for: list, mastodonController: mastodonController)
case let .savedHashtag(hashtag):
return HashtagTimelineViewController(for: hashtag, mastodonController: mastodonController)
case let .savedInstance(url):
return InstanceTimelineViewController(for: url, parentMastodonController: mastodonController)
default:
case .listsHeader, .addList, .savedHashtagsHeader, .addSavedHashtag, .savedInstancesHeader, .addSavedInstance:
return nil
}
}