Only show Trending Hashtags and Profile Directory on Mastodon
This commit is contained in:
parent
bbb8707cb7
commit
b0ebef2cfd
|
@ -115,6 +115,7 @@ class MastodonController: ObservableObject {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo: this should dedup requests
|
||||||
func getOwnInstance(completion: ((Instance) -> Void)? = nil) {
|
func getOwnInstance(completion: ((Instance) -> Void)? = nil) {
|
||||||
if let instance = self.instance {
|
if let instance = self.instance {
|
||||||
completion?(instance)
|
completion?(instance)
|
||||||
|
|
|
@ -51,6 +51,10 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate {
|
||||||
dataSource = createDataSource()
|
dataSource = createDataSource()
|
||||||
applyInitialSnapshot()
|
applyInitialSnapshot()
|
||||||
|
|
||||||
|
if mastodonController.instance == nil {
|
||||||
|
mastodonController.getOwnInstance(completion: self.ownInstanceLoaded(_:))
|
||||||
|
}
|
||||||
|
|
||||||
resultsController = SearchResultsViewController(mastodonController: mastodonController)
|
resultsController = SearchResultsViewController(mastodonController: mastodonController)
|
||||||
resultsController.exploreNavigationController = self.navigationController!
|
resultsController.exploreNavigationController = self.navigationController!
|
||||||
searchController = UISearchController(searchResultsController: resultsController)
|
searchController = UISearchController(searchResultsController: resultsController)
|
||||||
|
@ -132,9 +136,12 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate {
|
||||||
let account = mastodonController.accountInfo!
|
let account = mastodonController.accountInfo!
|
||||||
|
|
||||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||||
snapshot.appendSections(Section.allCases)
|
snapshot.appendSections(Section.allCases.filter { $0 != .discover })
|
||||||
snapshot.appendItems([.bookmarks], toSection: .bookmarks)
|
snapshot.appendItems([.bookmarks], toSection: .bookmarks)
|
||||||
|
if case .mastodon = mastodonController.instance?.instanceType {
|
||||||
|
snapshot.insertSections([.discover], afterSection: .bookmarks)
|
||||||
snapshot.appendItems([.trendingTags, .profileDirectory], toSection: .discover)
|
snapshot.appendItems([.trendingTags, .profileDirectory], toSection: .discover)
|
||||||
|
}
|
||||||
snapshot.appendItems([.addList], toSection: .lists)
|
snapshot.appendItems([.addList], toSection: .lists)
|
||||||
snapshot.appendItems(SavedDataManager.shared.sortedHashtags(for: account).map { .savedHashtag($0) }, toSection: .savedHashtags)
|
snapshot.appendItems(SavedDataManager.shared.sortedHashtags(for: account).map { .savedHashtag($0) }, toSection: .savedHashtags)
|
||||||
snapshot.appendItems([.addSavedHashtag], toSection: .savedHashtags)
|
snapshot.appendItems([.addSavedHashtag], toSection: .savedHashtags)
|
||||||
|
@ -145,6 +152,15 @@ class ExploreViewController: UIViewController, UICollectionViewDelegate {
|
||||||
reloadLists()
|
reloadLists()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func ownInstanceLoaded(_ instance: Instance) {
|
||||||
|
var snapshot = self.dataSource.snapshot()
|
||||||
|
if case .mastodon = instance.instanceType {
|
||||||
|
snapshot.insertSections([.discover], afterSection: .bookmarks)
|
||||||
|
snapshot.appendItems([.trendingTags, .profileDirectory], toSection: .discover)
|
||||||
|
}
|
||||||
|
self.dataSource.apply(snapshot)
|
||||||
|
}
|
||||||
|
|
||||||
private func reloadLists() {
|
private func reloadLists() {
|
||||||
let request = Client.getLists()
|
let request = Client.getLists()
|
||||||
mastodonController.run(request) { (response) in
|
mastodonController.run(request) { (response) in
|
||||||
|
|
|
@ -86,6 +86,10 @@ class MainSidebarViewController: UIViewController {
|
||||||
|
|
||||||
applyInitialSnapshot()
|
applyInitialSnapshot()
|
||||||
|
|
||||||
|
if mastodonController.instance == nil {
|
||||||
|
mastodonController.getOwnInstance(completion: self.ownInstanceLoaded(_:))
|
||||||
|
}
|
||||||
|
|
||||||
select(item: .tab(.timelines), animated: false)
|
select(item: .tab(.timelines), animated: false)
|
||||||
|
|
||||||
NotificationCenter.default.addObserver(self, selector: #selector(reloadSavedHashtags), name: .savedHashtagsChanged, object: nil)
|
NotificationCenter.default.addObserver(self, selector: #selector(reloadSavedHashtags), name: .savedHashtagsChanged, object: nil)
|
||||||
|
@ -130,7 +134,7 @@ class MainSidebarViewController: UIViewController {
|
||||||
|
|
||||||
private func applyInitialSnapshot() {
|
private func applyInitialSnapshot() {
|
||||||
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
var snapshot = NSDiffableDataSourceSnapshot<Section, Item>()
|
||||||
snapshot.appendSections(Section.allCases)
|
snapshot.appendSections(Section.allCases.filter { $0 != .discover })
|
||||||
snapshot.appendItems([
|
snapshot.appendItems([
|
||||||
.tab(.timelines),
|
.tab(.timelines),
|
||||||
.tab(.notifications),
|
.tab(.notifications),
|
||||||
|
@ -141,10 +145,13 @@ class MainSidebarViewController: UIViewController {
|
||||||
snapshot.appendItems([
|
snapshot.appendItems([
|
||||||
.tab(.compose)
|
.tab(.compose)
|
||||||
], toSection: .compose)
|
], toSection: .compose)
|
||||||
|
if case .mastodon = mastodonController.instance?.instanceType {
|
||||||
|
snapshot.insertSections([.discover], afterSection: .compose)
|
||||||
snapshot.appendItems([
|
snapshot.appendItems([
|
||||||
.trendingTags,
|
.trendingTags,
|
||||||
.profileDirectory,
|
.profileDirectory,
|
||||||
], toSection: .discover)
|
], toSection: .discover)
|
||||||
|
}
|
||||||
dataSource.apply(snapshot, animatingDifferences: false)
|
dataSource.apply(snapshot, animatingDifferences: false)
|
||||||
|
|
||||||
reloadLists()
|
reloadLists()
|
||||||
|
@ -152,6 +159,18 @@ class MainSidebarViewController: UIViewController {
|
||||||
reloadSavedInstances()
|
reloadSavedInstances()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func ownInstanceLoaded(_ instance: Instance) {
|
||||||
|
var snapshot = self.dataSource.snapshot()
|
||||||
|
if case .mastodon = mastodonController.instance?.instanceType {
|
||||||
|
snapshot.insertSections([.discover], afterSection: .compose)
|
||||||
|
snapshot.appendItems([
|
||||||
|
.trendingTags,
|
||||||
|
.profileDirectory,
|
||||||
|
], toSection: .discover)
|
||||||
|
}
|
||||||
|
dataSource.apply(snapshot, animatingDifferences: false)
|
||||||
|
}
|
||||||
|
|
||||||
private func reloadLists() {
|
private func reloadLists() {
|
||||||
let request = Client.getLists()
|
let request = Client.getLists()
|
||||||
mastodonController.run(request) { [weak self] (response) in
|
mastodonController.run(request) { [weak self] (response) in
|
||||||
|
|
Loading…
Reference in New Issue