Add Trending Posts/Links to sidebar

This commit is contained in:
Shadowfacts 2022-04-02 11:56:47 -04:00
parent cb2bb215d3
commit 829ecf06da
2 changed files with 39 additions and 16 deletions

View File

@ -32,7 +32,7 @@ class MainSidebarViewController: UIViewController {
}
var exploreTabItems: [Item] {
var items: [Item] = [.search, .bookmarks, .trendingTags, .profileDirectory]
var items: [Item] = [.search, .bookmarks, .trendingStatuses, .trendingTags, .trendingLinks, .profileDirectory]
let snapshot = dataSource.snapshot()
for case let .list(list) in snapshot.itemIdentifiers(inSection: .lists) {
items.append(.list(list))
@ -162,7 +162,9 @@ class MainSidebarViewController: UIViewController {
var discoverSnapshot = NSDiffableDataSourceSectionSnapshot<Item>()
discoverSnapshot.append([.discoverHeader])
discoverSnapshot.append([
.trendingStatuses,
.trendingTags,
.trendingLinks,
.profileDirectory,
], to: .discoverHeader)
dataSource.apply(discoverSnapshot, to: .discover)
@ -335,7 +337,7 @@ extension MainSidebarViewController {
enum Item: Hashable {
case tab(MainTabBarViewController.Tab)
case search, bookmarks
case discoverHeader, trendingTags, profileDirectory
case discoverHeader, trendingStatuses, trendingTags, trendingLinks, profileDirectory
case listsHeader, list(List), addList
case savedHashtagsHeader, savedHashtag(Hashtag), addSavedHashtag
case savedInstancesHeader, savedInstance(URL), addSavedInstance
@ -350,8 +352,12 @@ extension MainSidebarViewController {
return "Bookmarks"
case .discoverHeader:
return "Discover"
case .trendingStatuses:
return "Trending Posts"
case .trendingTags:
return "Trending Hashtags"
case .trendingLinks:
return "Trending Links"
case .profileDirectory:
return "Profile Directory"
case .listsHeader:
@ -383,8 +389,12 @@ extension MainSidebarViewController {
return "magnifyingglass"
case .bookmarks:
return "bookmark"
case .trendingStatuses:
return "doc.text.image"
case .trendingTags:
return "arrow.up.arrow.down"
return "number"
case .trendingLinks:
return "link"
case .profileDirectory:
return "person.2.fill"
case .list(_):

View File

@ -207,7 +207,7 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
tabBarViewController.select(tab: .explore)
case .bookmarks, .trendingTags, .profileDirectory, .list(_), .savedHashtag(_), .savedInstance(_):
case .bookmarks, .trendingStatuses, .trendingTags, .trendingLinks, .profileDirectory, .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.
@ -273,18 +273,27 @@ extension MainSplitViewController: UISplitViewControllerDelegate {
}
// Insert the new search VC at the beginning of the new search nav stack
toPrepend = searchVC
} else if tabNavigationStack[1] is BookmarksTableViewController {
exploreItem = .bookmarks
} else if let listVC = tabNavigationStack[1] as? ListTimelineViewController {
exploreItem = .list(listVC.list)
} else if let hashtagVC = tabNavigationStack[1] as? HashtagTimelineViewController {
exploreItem = .savedHashtag(hashtagVC.hashtag)
} else if let instanceVC = tabNavigationStack[1] as? InstanceTimelineViewController {
exploreItem = .savedInstance(instanceVC.instanceURL)
} else if tabNavigationStack[1] is TrendingHashtagsViewController {
exploreItem = .trendingTags
} else if tabNavigationStack[1] is ProfileDirectoryViewController {
exploreItem = .profileDirectory
} else {
switch tabNavigationStack[1] {
case is BookmarksTableViewController:
exploreItem = .bookmarks
case let listVC as ListTimelineViewController:
exploreItem = .list(listVC.list)
case let hashtagVC as HashtagTimelineViewController:
exploreItem = .savedHashtag(hashtagVC.hashtag)
case let instanceVC as InstanceTimelineViewController:
exploreItem = .savedInstance(instanceVC.instanceURL)
case is TrendingStatusesViewController:
exploreItem = .trendingStatuses
case is TrendingHashtagsViewController:
exploreItem = .trendingTags
case is TrendingLinksViewController:
exploreItem = .trendingLinks
case is ProfileDirectoryViewController:
exploreItem = .profileDirectory
default:
fatalError("unhandled second-level explore screen")
}
}
transferNavigationStack(from: tabNavController, to: exploreItem!, skipFirst: 1, prepend: toPrepend)
@ -335,8 +344,12 @@ fileprivate extension MainSidebarViewController.Item {
return SearchViewController(mastodonController: mastodonController)
case .bookmarks:
return BookmarksTableViewController(mastodonController: mastodonController)
case .trendingStatuses:
return TrendingStatusesViewController(mastodonController: mastodonController)
case .trendingTags:
return TrendingHashtagsViewController(mastodonController: mastodonController)
case .trendingLinks:
return TrendingLinksViewController(mastodonController: mastodonController)
case .profileDirectory:
return ProfileDirectoryViewController(mastodonController: mastodonController)
case let .list(list):