Skip to content

Commit

Permalink
fix(swiftui home): prevent crashes if for any reason some slates don'…
Browse files Browse the repository at this point in the history
…t contain all the recommendations (e.g. for a fetch error)
  • Loading branch information
Gio2018 committed Dec 13, 2024
1 parent 59a8110 commit 7b80db5
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions PocketKit/Sources/PocketKit/Home/Views/Card groups/SlateView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,19 @@ struct SlateView: View {
@EnvironmentObject var navigation: HomeNavigation

var body: some View {
VStack(alignment: .leading, spacing: 0) {
VStack(alignment: .leading, spacing: 16) {
if let slateTitle {
makeHeader(slateTitle)
if !cards.isEmpty {
VStack(alignment: .leading, spacing: 0) {
VStack(alignment: .leading, spacing: 16) {
if let slateTitle {
makeHeader(slateTitle)
}
HeroView(remoteID: remoteID, cards: heroCards)
}
HeroView(remoteID: remoteID, cards: heroCards)
.padding(EdgeInsets(top: 16, leading: 16, bottom: 0, trailing: 16))
CarouselView(cards: carouselCards, useGrid: layoutWidth.isRegular)
}
.padding(EdgeInsets(top: 16, leading: 16, bottom: 0, trailing: 16))
CarouselView(cards: carouselCards, useGrid: layoutWidth.isRegular)
.padding(.bottom, 32)
}
.padding(.bottom, 32)
}
}

Expand All @@ -49,7 +51,7 @@ private extension SlateView {

/// Determines how many hero cells should be used
var heroCount: Int {
Self.heroCount(layoutWidth.isRegular)
min(Self.heroCount(layoutWidth.isRegular), cards.count)
}

/// Extract the Hero recommendations
Expand Down

0 comments on commit 7b80db5

Please sign in to comment.