Skip to content

Commit da7dc5b

Browse files
authored
SwiftUI Home - Prevent crash if slates don't load (#1130)
fix(swiftui home): prevent crashes if for any reason some slates don't contain all the recommendations (e.g. for a fetch error)
1 parent 59a8110 commit da7dc5b

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

PocketKit/Sources/PocketKit/Home/Views/Card groups/SlateView.swift

+11-9
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,19 @@ struct SlateView: View {
1919
@EnvironmentObject var navigation: HomeNavigation
2020

2121
var body: some View {
22-
VStack(alignment: .leading, spacing: 0) {
23-
VStack(alignment: .leading, spacing: 16) {
24-
if let slateTitle {
25-
makeHeader(slateTitle)
22+
if !cards.isEmpty {
23+
VStack(alignment: .leading, spacing: 0) {
24+
VStack(alignment: .leading, spacing: 16) {
25+
if let slateTitle {
26+
makeHeader(slateTitle)
27+
}
28+
HeroView(remoteID: remoteID, cards: heroCards)
2629
}
27-
HeroView(remoteID: remoteID, cards: heroCards)
30+
.padding(EdgeInsets(top: 16, leading: 16, bottom: 0, trailing: 16))
31+
CarouselView(cards: carouselCards, useGrid: layoutWidth.isRegular)
2832
}
29-
.padding(EdgeInsets(top: 16, leading: 16, bottom: 0, trailing: 16))
30-
CarouselView(cards: carouselCards, useGrid: layoutWidth.isRegular)
33+
.padding(.bottom, 32)
3134
}
32-
.padding(.bottom, 32)
3335
}
3436
}
3537

@@ -49,7 +51,7 @@ private extension SlateView {
4951

5052
/// Determines how many hero cells should be used
5153
var heroCount: Int {
52-
Self.heroCount(layoutWidth.isRegular)
54+
min(Self.heroCount(layoutWidth.isRegular), cards.count)
5355
}
5456

5557
/// Extract the Hero recommendations

0 commit comments

Comments
 (0)