1.2.1: surface "Copy previous week" on the empty-week banner

The exact-copy-from-previous-week action already existed but was buried in the
magic-wand long-press context menu. Expose it as a visible secondary button on
the auto-assign banner (shown only when the previous week actually has a menu),
so users landing on a fresh week can one-tap copy last week's plan and then tweak
it. Confirms before overwriting a week that already has dishes.

- Extract requestCopyPreviousWeek() shared by the menu and the banner.
- Add week_copied_previous analytics (copied_slots + source: empty_banner|menu).
- Reuses the existing localized home_copy_previous_week string (all 6 languages).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BkanrydYtrme8wipTzWssG
This commit is contained in:
alexandrev-tibco
2026-07-11 10:58:53 +02:00
parent c5fd1088cd
commit 6ba71e6341
3 changed files with 78 additions and 31 deletions
+5 -1
View File
@@ -266,7 +266,8 @@ final class HomeViewModel: ObservableObject {
previousPlan: WeekPlan?,
settings: AppSettings,
allTags: [Tag],
allDishes: [Dish]
allDishes: [Dish],
source: String
) {
guard let previousPlan else {
showToastMessage(localizedString("toast_previous_week_empty", language: settings.languageEnum.resolved()))
@@ -282,6 +283,7 @@ final class HomeViewModel: ObservableObject {
}
let dishIds = Set(allDishes.map(\.id))
var copiedCount = 0
for slot in currentPlan.slots {
if let eventId = slot.calendarEventId {
CalendarService.shared.deleteEvent(eventId: eventId)
@@ -291,6 +293,7 @@ final class HomeViewModel: ObservableObject {
let key = SlotKey(dayOfWeek: slot.dayOfWeek, mealType: slot.mealType)
if let previousDishId = previousByKey[key]?.dishId, dishIds.contains(previousDishId) {
slot.dishId = previousDishId
copiedCount += 1
} else {
slot.dishId = nil
}
@@ -301,6 +304,7 @@ final class HomeViewModel: ObservableObject {
currentPlan.updatedAt = Date()
applyCalendarSyncPolicy(plan: currentPlan, settings: settings)
HapticManager.shared.notification(type: .success)
AnalyticsService.logWeekCopiedPrevious(copiedSlots: copiedCount, source: source)
showToastMessage(localizedString("toast_copied_previous_week", language: settings.languageEnum.resolved()))
}