platos: segundo plato por comida (ensalada + salmon)

- MealSlot.secondaryDishId (opcional, aditivo CloudKit); se limpia al
  sustituir/quitar/vaciar/marcar comer fuera y viaja en swaps, copia de
  semana anterior, undo y snapshot KV de iCloud (retrocompatible)
- Picker de hueco lleno: toggle "anadir como segundo plato" + boton para
  quitarlo; HomeViewModel.assignSecondaryDish/removeSecondaryDish
- Se muestra "Plato + Segundo" en calendario, widget y export; la lista
  de la compra incluye los ingredientes del segundo; stats lo cuentan
- Evento analytics secondary_dish_added; strings en 6 idiomas

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:37:23 +02:00
parent 7193234024
commit a0f9fa63d3
15 changed files with 128 additions and 13 deletions
+49 -2
View File
@@ -570,7 +570,23 @@ struct HomeView: View {
DispatchQueue.main.asyncAfter(deadline: .now() + 0.15) {
attemptCreateDish()
}
}
},
onPickSecondDish: { dish in
guard let freshSlot = plan.slotList.first(where: { $0.id == slotId }) else {
selectedFilledSlotId = nil
return
}
viewModel.assignSecondaryDish(dish, to: freshSlot, plan: plan, settings: settings)
selectedFilledSlotId = nil
},
onRemoveSecondDish: plan.slotList.first(where: { $0.id == slotId })?.secondaryDishId != nil ? {
guard let freshSlot = plan.slotList.first(where: { $0.id == slotId }) else {
selectedFilledSlotId = nil
return
}
viewModel.removeSecondaryDish(from: freshSlot, plan: plan)
selectedFilledSlotId = nil
} : nil
)
}
}
@@ -673,9 +689,14 @@ struct HomeView: View {
let onPickDish: (Dish) -> Void
let onCreateDish: () -> Void
var onEatingOut: (() -> Void)? = nil
/// Set for filled slots: taps add a companion dish instead of replacing
/// when the "second dish" mode is on.
var onPickSecondDish: ((Dish) -> Void)? = nil
var onRemoveSecondDish: (() -> Void)? = nil
@Environment(\.dismiss) private var dismiss
@State private var searchText: String = ""
@State private var asSecondDish: Bool = false
private var filteredDishes: [Dish] {
let trimmed = searchText.trimmingCharacters(in: .whitespacesAndNewlines)
@@ -720,9 +741,35 @@ struct HomeView: View {
.listRowBackground(Color(hex: "#EEF8F5"))
}
if onPickSecondDish != nil, searchText.isEmpty {
Toggle(isOn: $asSecondDish) {
Label("home_pick_second_dish", systemImage: "plus.square.on.square")
.font(.mealMoodBody)
.foregroundColor(.mealMoodTextPrimary)
}
.tint(.mealMoodCoral)
.listRowBackground(Color.mealMoodSurface)
if let onRemoveSecondDish {
Button {
dismiss()
onRemoveSecondDish()
} label: {
Label("home_remove_second_dish", systemImage: "minus.square")
.font(.mealMoodBody)
.foregroundColor(.mealMoodError)
}
.listRowBackground(Color.mealMoodSurface)
}
}
ForEach(filteredDishes, id: \.id) { dish in
Button {
onPickDish(dish)
if asSecondDish, let onPickSecondDish {
onPickSecondDish(dish)
} else {
onPickDish(dish)
}
dismiss()
} label: {
VStack(alignment: .leading, spacing: 6) {