From 13cdb5d8c7bee0ac00c8190ee6be318db7b0ac19 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 7 Feb 2021 10:45:36 -0500 Subject: [PATCH] Add Trending Hashtags to sidebar --- Tusker/Screens/Main/MainSidebarViewController.swift | 11 ++++++++++- Tusker/Screens/Main/MainSplitViewController.swift | 8 ++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/Tusker/Screens/Main/MainSidebarViewController.swift b/Tusker/Screens/Main/MainSidebarViewController.swift index 7e7fce28..71830354 100644 --- a/Tusker/Screens/Main/MainSidebarViewController.swift +++ b/Tusker/Screens/Main/MainSidebarViewController.swift @@ -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(_): diff --git a/Tusker/Screens/Main/MainSplitViewController.swift b/Tusker/Screens/Main/MainSplitViewController.swift index ae4489f6..90a1825f 100644 --- a/Tusker/Screens/Main/MainSplitViewController.swift +++ b/Tusker/Screens/Main/MainSplitViewController.swift @@ -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 } }