platos: paywall inmediato al llegar al limite y orden alfabetico

- attemptAddDish/attemptCreateDish: el limite gratuito se comprueba en el
  tap de anadir plato (DishListView y los 3 puntos de Home) y muestra el
  DishLimitModal -> paywall directamente; antes solo se comprobaba al
  guardar el formulario y el usuario podia rellenarlo entero para nada
- DishLimitModal compartido (era private de DishFormView) y
  PaywallPresentation promovido a PremiumView.swift; DishListView usa
  sheet(item:) tambien para el banner (source dish_counter vs dish_limit)
- Boton en la toolbar de Mis Platos que alterna orden alfabetico
  (persistido en dish_list_alphabetical_sort); borrado por swipe corregido
  para usar la lista mostrada

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013H6bXqGX1ygwib1Dm3n3UG
This commit is contained in:
alexandrev-tibco
2026-09-01 11:18:34 +02:00
parent f51f975941
commit 47daab9e51
10 changed files with 97 additions and 17 deletions
+51 -8
View File
@@ -10,12 +10,19 @@ struct DishListView: View {
@State private var showDishForm = false
@State private var editingDish: Dish?
@State private var showDeleteBlockedAlert = false
@State private var showPremium = false
@State private var showDishLimitModal = false
@State private var paywallPresentation: PaywallPresentation?
@AppStorage("dish_list_alphabetical_sort") private var alphabeticalSort = false
private var language: AppLanguage {
(allSettings.first?.languageEnum ?? .system).resolved()
}
private var displayedDishes: [Dish] {
guard alphabeticalSort else { return dishes }
return dishes.sorted { $0.name.localizedCaseInsensitiveCompare($1.name) == .orderedAscending }
}
var body: some View {
ZStack {
Color.mealMoodBackground.ignoresSafeArea()
@@ -28,7 +35,7 @@ struct DishListView: View {
Text("dish_list_empty")
.font(.mealMoodBody)
.foregroundColor(.mealMoodTextSecondary)
PrimaryButton(title: String(localized: "home_add_dish"), action: { showDishForm = true })
PrimaryButton(title: String(localized: "home_add_dish"), action: attemptAddDish)
.padding(.horizontal, 60)
}
} else {
@@ -37,7 +44,7 @@ struct DishListView: View {
dishCounterBanner
}
List {
ForEach(dishes, id: \.id) { dish in
ForEach(displayedDishes, id: \.id) { dish in
let dishTags = tags.filter { dish.tagIds.contains($0.id) }
Button {
editingDish = dish
@@ -77,18 +84,40 @@ struct DishListView: View {
.toolbar {
ToolbarItem(placement: .navigationBarTrailing) {
Button {
showDishForm = true
withAnimation { alphabeticalSort.toggle() }
} label: {
Image(systemName: "arrow.up.arrow.down")
.foregroundColor(alphabeticalSort ? .mealMoodCoral : .mealMoodTextSecondary)
}
.accessibilityLabel(Text("dish_sort_alphabetical"))
}
ToolbarItem(placement: .navigationBarTrailing) {
Button {
attemptAddDish()
} label: {
Image(systemName: "plus")
.foregroundColor(.mealMoodCoral)
}
}
}
.sheet(isPresented: $showPremium) {
.sheet(item: $paywallPresentation) { presentation in
if let settings = allSettings.first {
NavigationStack { PremiumView(settings: settings, source: "dish_counter") }
NavigationStack { PremiumView(settings: settings, source: presentation.source) }
}
}
.sheet(isPresented: $showDishLimitModal) {
DishLimitModal(
onSeePremium: {
showDishLimitModal = false
DispatchQueue.main.asyncAfter(deadline: .now() + 0.35) {
paywallPresentation = PaywallPresentation(source: "dish_limit")
}
},
onDismiss: { showDishLimitModal = false }
)
.presentationDetents([.medium])
.presentationDragIndicator(.visible)
}
.sheet(isPresented: $showDishForm) {
DishFormView()
}
@@ -110,7 +139,7 @@ struct DishListView: View {
let accent: Color = isNearLimit ? .mealMoodCoral : .mealMoodTextSecondary
return Button {
showPremium = true
paywallPresentation = PaywallPresentation(source: "dish_counter")
} label: {
HStack(spacing: 10) {
Image(systemName: isNearLimit ? "exclamationmark.circle.fill" : "star.circle")
@@ -143,12 +172,26 @@ struct DishListView: View {
.padding(.bottom, 4)
}
/// Same gate as the form's save button, but at the entry point: a user at
/// the free limit gets the paywall on tapping "add", not after filling in
/// a dish they can't save.
private func attemptAddDish() {
let isPremium = allSettings.first?.isPremium ?? false
if PremiumAccess.hasReachedFreeDishLimit(dishCount: dishes.count, isPremium: isPremium) {
AnalyticsService.logDishLimitHit()
HapticManager.shared.notification(type: .warning)
showDishLimitModal = true
} else {
showDishForm = true
}
}
private func deleteDishes(at offsets: IndexSet) {
let currentWeekStart = Date().startOfWeek()
let currentWeekPlan = weekPlans.first { $0.weekStartDate == currentWeekStart }
for index in offsets {
let dish = dishes[index]
let dish = displayedDishes[index]
if currentWeekPlan?.slotList.contains(where: { $0.dishId == dish.id }) == true {
showDeleteBlockedAlert = true
continue