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

View File

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