Skip to content

Commit cfef38f

Browse files
authored
Merge pull request #598 from synonymdev/fix/reset-suggestions-when-empty
fix: reset suggestions widget when re-added empty
2 parents b0185fa + 11b91aa commit cfef38f

4 files changed

Lines changed: 59 additions & 6 deletions

File tree

Bitkit/Components/Widgets/Suggestions.swift

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ struct Suggestions: View {
164164
/// When true, show a fixed set of static cards and ignore taps (e.g. widget preview).
165165
var isPreview: Bool = false
166166

167+
/// When editing the home grid, keep the widget visible (and reorderable/removable) by falling
168+
/// back to the static preview set when there are no live cards to show.
169+
var isEditing: Bool = false
170+
167171
var previewCardIds: [String]?
168172

169173
static let previewSheetCardIds = ["backupSeedPhrase", "pin", "transferToSpending", "support"]
@@ -250,8 +254,30 @@ struct Suggestions: View {
250254
)
251255
}
252256

257+
private var isEditingFallback: Bool {
258+
isEditing && !isPreview && visibleCards.isEmpty
259+
}
260+
261+
private var cardsToShow: [SuggestionCardData] {
262+
guard isEditingFallback else { return visibleCards }
263+
return Self.visibleCards(
264+
wallet: wallet,
265+
app: app,
266+
settings: settings,
267+
suggestionsManager: suggestionsManager,
268+
pubkyProfile: pubkyProfile,
269+
isPaykitUIEnabled: isPaykitUIActive,
270+
isPreview: true,
271+
previewCardIds: Self.previewSheetCardIds
272+
)
273+
}
274+
275+
private var renderStatic: Bool {
276+
isPreview || isEditingFallback
277+
}
278+
253279
var body: some View {
254-
if visibleCards.isEmpty {
280+
if cardsToShow.isEmpty {
255281
EmptyView()
256282
} else {
257283
LazyVGrid(
@@ -261,25 +287,25 @@ struct Suggestions: View {
261287
],
262288
spacing: 16
263289
) {
264-
ForEach(visibleCards) { card in
290+
ForEach(cardsToShow) { card in
265291
SuggestionCard(
266292
title: card.title,
267293
description: card.description,
268294
imageName: card.imageName,
269295
accentColor: card.color,
270-
onTap: { if !isPreview { onItemTap(card) } },
296+
onTap: { if !renderStatic { onItemTap(card) } },
271297
onDismiss: { dismissCard(card) }
272298
)
273299
.background {
274-
if isPreview {
300+
if renderStatic {
275301
RoundedRectangle(cornerRadius: 16).fill(Color.black)
276302
}
277303
}
278304
.accessibilityElement(children: .contain)
279305
.accessibilityIdentifier("Suggestion-\(card.accessibilityId)")
280306
}
281307
}
282-
.allowsHitTesting(!isPreview)
308+
.allowsHitTesting(!renderStatic)
283309
.sheet(isPresented: $showShareSheet) {
284310
ShareSheet(activityItems: [
285311
t(

Bitkit/Components/Widgets/SuggestionsWidget.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct SuggestionsWidget: View {
1313
hasBackground: false,
1414
onEditingEnd: onEditingEnd
1515
) {
16-
Suggestions(isPreview: isPreview)
16+
Suggestions(isPreview: isPreview, isEditing: isEditing)
1717
}
1818
}
1919
}

Bitkit/Views/Widgets/WidgetPreviewSheetView.swift

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@ struct WidgetPreviewSheetView: View {
99
@EnvironmentObject private var app: AppViewModel
1010
@EnvironmentObject private var currency: CurrencyViewModel
1111
@EnvironmentObject private var navigation: NavigationViewModel
12+
@EnvironmentObject private var pubkyProfile: PubkyProfileManager
13+
@EnvironmentObject private var settings: SettingsViewModel
1214
@EnvironmentObject private var sheets: SheetViewModel
15+
@EnvironmentObject private var suggestionsManager: SuggestionsManager
16+
@EnvironmentObject private var wallet: WalletViewModel
1317
@EnvironmentObject private var widgets: WidgetsViewModel
1418

19+
@AppStorage(PaykitFeatureFlags.uiEnabledKey) private var isPaykitUIEnabled = false
20+
1521
@State private var carouselPage: Int
1622
@State private var showDeleteAlert = false
1723

@@ -55,6 +61,23 @@ struct WidgetPreviewSheetView: View {
5561
carouselPage == 0 && supportsSmall ? .small : .wide
5662
}
5763

64+
private var isPaykitUIActive: Bool {
65+
PaykitFeatureFlags.isUIAvailable && isPaykitUIEnabled
66+
}
67+
68+
/// Whether the Suggestions widget would currently show no cards (mirrors what the live
69+
/// `Suggestions` view renders, including the `pubkyProfile` completion check).
70+
private var suggestionsAreEmpty: Bool {
71+
Suggestions.visibleCards(
72+
wallet: wallet,
73+
app: app,
74+
settings: settings,
75+
suggestionsManager: suggestionsManager,
76+
pubkyProfile: pubkyProfile,
77+
isPaykitUIEnabled: isPaykitUIActive
78+
).isEmpty
79+
}
80+
5881
var body: some View {
5982
VStack(alignment: .leading, spacing: 16) {
6083
SheetHeader(title: metadata.name, showBackButton: true)
@@ -261,6 +284,9 @@ struct WidgetPreviewSheetView: View {
261284
// MARK: - Actions
262285

263286
private func onSave() {
287+
if type == .suggestions, suggestionsAreEmpty {
288+
suggestionsManager.resetDismissed()
289+
}
264290
widgets.saveWidget(type, size: chosenSize)
265291
sheets.hideSheet()
266292
navigation.reset()

changelog.d/next/596.fixed.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Re-adding the Suggestions widget now restores the default suggestion cards when all of them had been dismissed.

0 commit comments

Comments
 (0)