Fix wrong cells on trending links screen being selectable

This commit is contained in:
Shadowfacts 2023-02-11 18:23:53 -05:00
parent 841119949b
commit ae7ca9c91c
1 changed files with 13 additions and 1 deletions

View File

@ -175,7 +175,7 @@ class TrendingLinksViewController: UIViewController, CollectionViewController {
do { do {
let request = Client.getTrendingLinks(offset: origSnapshot.itemIdentifiers.count) let request = Client.getTrendingLinks(offset: origSnapshot.itemIdentifiers.count)
let (links, _) = try await mastodonController.run(request) let (links, _) = try await mastodonController.run(request)
snapshot = origSnapshot var snapshot = origSnapshot
snapshot.appendItems(links.map { .link($0) }, toSection: .links) snapshot.appendItems(links.map { .link($0) }, toSection: .links)
await dataSource.apply(snapshot) await dataSource.apply(snapshot)
} catch { } catch {
@ -235,6 +235,14 @@ extension TrendingLinksViewController {
hasher.combine(loading) hasher.combine(loading)
} }
} }
var shouldSelect: Bool {
if case .link(_) = self {
return true
} else {
return false
}
}
} }
} }
@ -248,6 +256,10 @@ extension TrendingLinksViewController: UICollectionViewDelegate {
} }
} }
func collectionView(_ collectionView: UICollectionView, shouldSelectItemAt indexPath: IndexPath) -> Bool {
return dataSource.itemIdentifier(for: indexPath)?.shouldSelect ?? false
}
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard case .link(let card) = dataSource.itemIdentifier(for: indexPath), guard case .link(let card) = dataSource.itemIdentifier(for: indexPath),
let url = URL(card.url) else { let url = URL(card.url) else {