From ea85b1194552e837f28b3d867e43d94a5da43bf3 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 11 Feb 2023 10:09:56 -0500 Subject: [PATCH] Use cards for trending links screen, and add pagination See #355 --- .../Pachyderm/Sources/Pachyderm/Client.swift | 13 +- .../TrendingLinkCardCollectionViewCell.swift | 31 +++ .../TrendingLinkCardCollectionViewCell.xib | 6 +- .../Explore/TrendingLinksViewController.swift | 259 +++++++++++++++--- .../ConfirmLoadMoreCollectionViewCell.swift | 2 +- 5 files changed, 256 insertions(+), 55 deletions(-) diff --git a/Packages/Pachyderm/Sources/Pachyderm/Client.swift b/Packages/Pachyderm/Sources/Pachyderm/Client.swift index 57422227..cd6c3889 100644 --- a/Packages/Pachyderm/Sources/Pachyderm/Client.swift +++ b/Packages/Pachyderm/Sources/Pachyderm/Client.swift @@ -437,12 +437,13 @@ public class Client { return Request(method: .get, path: "/api/v1/trends/statuses", queryParameters: parameters) } - public static func getTrendingLinks(limit: Int? = nil) -> Request<[Card]> { - let parameters: [Parameter] - if let limit = limit { - parameters = ["limit" => limit] - } else { - parameters = [] + public static func getTrendingLinks(limit: Int? = nil, offset: Int? = nil) -> Request<[Card]> { + var parameters: [Parameter] = [] + if let limit { + parameters.append("limit" => limit) + } + if let offset { + parameters.append("offset" => offset) } return Request(method: .get, path: "/api/v1/trends/links", queryParameters: parameters) } diff --git a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift index 98bea58c..1a88dec3 100644 --- a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift +++ b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.swift @@ -21,6 +21,29 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { @IBOutlet weak var providerLabel: UILabel! @IBOutlet weak var activityLabel: UILabel! @IBOutlet weak var historyView: TrendHistoryView! + private var thumbnailAspectRatioConstraint: NSLayoutConstraint? + + var verticalSize: VerticalSize! { + didSet { + guard oldValue != verticalSize else { + return + } + switch verticalSize { + case nil: + fatalError() + case .regular: + thumbnailAspectRatioConstraint?.isActive = false + thumbnailAspectRatioConstraint = thumbnailView.widthAnchor.constraint(equalTo: thumbnailView.heightAnchor, multiplier: 4/3) + thumbnailAspectRatioConstraint!.isActive = true + descriptionLabel.numberOfLines = 3 + case .compact: + thumbnailAspectRatioConstraint?.isActive = false + thumbnailAspectRatioConstraint = thumbnailView.widthAnchor.constraint(equalTo: thumbnailView.heightAnchor, multiplier: 2/1) + thumbnailAspectRatioConstraint!.isActive = true + descriptionLabel.numberOfLines = 5 + } + } + } private var hoverGestureAnimator: UIViewPropertyAnimator? @@ -37,6 +60,8 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { contentView.backgroundColor = .appGroupedCellBackground updateLayerColors() + verticalSize = .regular + addGestureRecognizer(UIHoverGestureRecognizer(target: self, action: #selector(hoverRecognized))) } @@ -137,3 +162,9 @@ class TrendingLinkCardCollectionViewCell: UICollectionViewCell { } } + +extension TrendingLinkCardCollectionViewCell { + enum VerticalSize { + case regular, compact + } +} diff --git a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib index 23391e6d..3a111877 100644 --- a/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib +++ b/Tusker/Screens/Explore/TrendingLinkCardCollectionViewCell.xib @@ -21,7 +21,7 @@ - + @@ -56,9 +56,9 @@ - + - +