From 270cbc2a6cb196ef9713af63ee5ec4435570520f Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Tue, 17 Dec 2019 18:48:29 -0500 Subject: [PATCH] Add lists to Explore tab Closes #63 --- Pachyderm/Model/List.swift | 4 ++ Tusker.xcodeproj/project.pbxproj | 12 +++++ .../Explore/ExploreViewController.swift | 47 ++++++++++++++++--- .../Lists/ListTimelineViewController.swift | 28 +++++++++++ 4 files changed, 85 insertions(+), 6 deletions(-) create mode 100644 Tusker/Screens/Lists/ListTimelineViewController.swift diff --git a/Pachyderm/Model/List.swift b/Pachyderm/Model/List.swift index 19804c06..b53f78dc 100644 --- a/Pachyderm/Model/List.swift +++ b/Pachyderm/Model/List.swift @@ -12,6 +12,10 @@ public class List: Decodable { public let id: String public let title: String + public var timeline: Timeline { + return .list(id: id) + } + public static func getAccounts(_ list: List, range: RequestRange = .default) -> Request<[Account]> { var request = Request<[Account]>(method: .get, path: "/api/v1/lists/\(list.id)/accounts") request.range = range diff --git a/Tusker.xcodeproj/project.pbxproj b/Tusker.xcodeproj/project.pbxproj index 943e11f7..09937243 100644 --- a/Tusker.xcodeproj/project.pbxproj +++ b/Tusker.xcodeproj/project.pbxproj @@ -84,6 +84,7 @@ D627943E23A564D400D38C68 /* ExploreViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627943D23A564D400D38C68 /* ExploreViewController.swift */; }; D627944723A6AC9300D38C68 /* BasicTableViewCell.xib in Resources */ = {isa = PBXBuildFile; fileRef = D627944623A6AC9300D38C68 /* BasicTableViewCell.xib */; }; D627944A23A6AD6100D38C68 /* BookmarksTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627944923A6AD6100D38C68 /* BookmarksTableViewController.swift */; }; + D627944D23A9A03D00D38C68 /* ListTimelineViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627944C23A9A03D00D38C68 /* ListTimelineViewController.swift */; }; D627FF76217E923E00CC0648 /* DraftsManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF75217E923E00CC0648 /* DraftsManager.swift */; }; D627FF79217E950100CC0648 /* DraftsTableViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = D627FF78217E950100CC0648 /* DraftsTableViewController.xib */; }; D627FF7B217E951500CC0648 /* DraftsTableViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */; }; @@ -355,6 +356,7 @@ D627943D23A564D400D38C68 /* ExploreViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExploreViewController.swift; sourceTree = ""; }; D627944623A6AC9300D38C68 /* BasicTableViewCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = BasicTableViewCell.xib; sourceTree = ""; }; D627944923A6AD6100D38C68 /* BookmarksTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BookmarksTableViewController.swift; sourceTree = ""; }; + D627944C23A9A03D00D38C68 /* ListTimelineViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListTimelineViewController.swift; sourceTree = ""; }; D627FF75217E923E00CC0648 /* DraftsManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsManager.swift; sourceTree = ""; }; D627FF78217E950100CC0648 /* DraftsTableViewController.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = DraftsTableViewController.xib; sourceTree = ""; }; D627FF7A217E951500CC0648 /* DraftsTableViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DraftsTableViewController.swift; sourceTree = ""; }; @@ -739,6 +741,14 @@ path = Bookmarks; sourceTree = ""; }; + D627944B23A9A02400D38C68 /* Lists */ = { + isa = PBXGroup; + children = ( + D627944C23A9A03D00D38C68 /* ListTimelineViewController.swift */, + ); + path = Lists; + sourceTree = ""; + }; D627FF77217E94F200CC0648 /* Drafts */ = { isa = PBXGroup; children = ( @@ -774,6 +784,7 @@ D641C787213DD862004B4513 /* Compose */, D627943C23A5635D00D38C68 /* Explore */, D6BC9DD8232D8BCA002CA326 /* Search */, + D627944B23A9A02400D38C68 /* Lists */, D641C788213DD86D004B4513 /* Large Image */, 0411610422B4571E0030A9B7 /* Attachment */, 0411610522B457290030A9B7 /* Gallery */, @@ -1632,6 +1643,7 @@ D6BC9DD7232D7811002CA326 /* TimelinesPageViewController.swift in Sources */, D6028B9B2150811100F223B9 /* MastodonCache.swift in Sources */, D6A3BC802321B7E600FD64D5 /* FollowNotificationGroupTableViewCell.swift in Sources */, + D627944D23A9A03D00D38C68 /* ListTimelineViewController.swift in Sources */, D62D2422217AA7E1005076CC /* UserActivityManager.swift in Sources */, D60D2B8223844C71001B87A3 /* BaseStatusTableViewCell.swift in Sources */, D62D2424217ABF3F005076CC /* NSUserActivity+Extensions.swift in Sources */, diff --git a/Tusker/Screens/Explore/ExploreViewController.swift b/Tusker/Screens/Explore/ExploreViewController.swift index 72a20262..af496044 100644 --- a/Tusker/Screens/Explore/ExploreViewController.swift +++ b/Tusker/Screens/Explore/ExploreViewController.swift @@ -8,6 +8,7 @@ import UIKit import Combine +import Pachyderm class ExploreViewController: EnhancedTableViewController { @@ -43,10 +44,10 @@ class ExploreViewController: EnhancedTableViewController { cell.accessoryType = .disclosureIndicator return cell - case let .list(id): + case let .list(list): let cell = tableView.dequeueReusableCell(withIdentifier: "basicCell", for: indexPath) cell.imageView!.image = nil - cell.textLabel!.text = id + cell.textLabel!.text = list.title cell.accessoryType = .disclosureIndicator return cell } @@ -70,8 +71,22 @@ class ExploreViewController: EnhancedTableViewController { navigationItem.searchController = searchController navigationItem.hidesSearchBarWhenScrolling = false + + let request = MastodonController.client.getLists() + MastodonController.client.run(request) { (response) in + guard case let .success(lists, _) = response else { + fatalError() + } + + var snapshot = self.dataSource.snapshot() + snapshot.appendItems(lists.map { .list($0) }, toSection: .lists) + + DispatchQueue.main.async { + self.dataSource.apply(snapshot) + } + } } - + // MARK: - Table view delegate override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { @@ -82,8 +97,8 @@ class ExploreViewController: EnhancedTableViewController { case .bookmarks: show(BookmarksTableViewController(), sender: nil) - case let .list(id): - show(TimelineTableViewController(for: .list(id: id)), sender: nil) + case let .list(list): + show(ListTimelineViewController(for: list), sender: nil) } } @@ -96,7 +111,27 @@ extension ExploreViewController { } enum Item: Hashable { case bookmarks - case list(id: String) + case list(List) + + static func == (lhs: ExploreViewController.Item, rhs: ExploreViewController.Item) -> Bool { + switch (lhs, rhs) { + case (.bookmarks, .bookmarks): + return true + case let (.list(a), .list(b)): + return a.id == b.id + default: + return false + } + } + func hash(into hasher: inout Hasher) { + switch self { + case .bookmarks: + hasher.combine("bookmarks") + case let .list(list): + hasher.combine("list") + hasher.combine(list.id) + } + } } class DataSource: UITableViewDiffableDataSource { override func tableView(_ tableView: UITableView, titleForHeaderInSection section: Int) -> String? { diff --git a/Tusker/Screens/Lists/ListTimelineViewController.swift b/Tusker/Screens/Lists/ListTimelineViewController.swift new file mode 100644 index 00000000..4103ec2c --- /dev/null +++ b/Tusker/Screens/Lists/ListTimelineViewController.swift @@ -0,0 +1,28 @@ +// +// ListTimelineViewController.swift +// Tusker +// +// Created by Shadowfacts on 12/17/19. +// Copyright © 2019 Shadowfacts. All rights reserved. +// + +import UIKit +import Pachyderm + +class ListTimelineViewController: TimelineTableViewController { + + let list: List + + init(for list: List) { + self.list = list + + super.init(for: .list(id: list.id)) + + title = list.title + } + + required init?(coder aDecoder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } + +}