2.0: breakfast and snack meal types across the app
- MealType gains breakfast/snack (chronological order drives slot/row order). - AppSettings.activeMealTypes: single source of truth for enabled meals, backed by new optional enabledMealTypesRaw with legacy mealWindows fallback — additive migration, keeps pre-2.0 installs and iCloud snapshots working. Legacy field kept coherent by the setter. time(for:) resolves per-meal event times (breakfast 8:00 / snack 17:00 defaults on old stores). - Replaced the 5 duplicated mealWindows→[MealType] derivations (slot sync, default plan creation, week calendar, export view) with activeMealTypes. - CalendarService: per-type event names and times. - Export styles: per-type accent colors and gradients. - Widget: generic meals list (N rows) instead of hardcoded lunch/dinner; compact families fall back to main meals when >2 are active. - Settings: 4 meal toggles (min 1) replace the 3-option picker. - Onboarding: meal step is now multi-select over the 4 types. - iCloud sync: enabledMealTypesRaw synced (optional, pre-2.0 compatible). - Localized breakfast/snack in 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:
@@ -1,11 +1,16 @@
|
||||
import Foundation
|
||||
import WidgetKit
|
||||
|
||||
/// Snapshot of today's meals for the widget. Generic over meal types (2.0):
|
||||
/// one entry per active meal type, in chronological order.
|
||||
struct TodayMealData: Codable {
|
||||
let lunch: String?
|
||||
let dinner: String?
|
||||
let lunchLabel: String
|
||||
let dinnerLabel: String
|
||||
struct Meal: Codable {
|
||||
let type: String // MealType raw value (drives icon/color in widget)
|
||||
let label: String // localized meal name
|
||||
let name: String? // dish name, nil when the slot is empty
|
||||
}
|
||||
|
||||
let meals: [Meal]
|
||||
let weekdayName: String
|
||||
let updatedAt: Date
|
||||
}
|
||||
@@ -20,11 +25,17 @@ enum WidgetDataStore {
|
||||
// weekday: 1=Sun,2=Mon..7=Sat → appDayOfWeek: 0=Mon..6=Sun
|
||||
let appDayOfWeek = (weekday + 5) % 7
|
||||
|
||||
let lunchId = plan?.slots.first { $0.dayOfWeek == appDayOfWeek && $0.mealType == MealType.lunch.rawValue }?.dishId
|
||||
let dinnerId = plan?.slots.first { $0.dayOfWeek == appDayOfWeek && $0.mealType == MealType.dinner.rawValue }?.dishId
|
||||
|
||||
let lunch = lunchId.flatMap { id in dishes.first { $0.id == id }?.name }
|
||||
let dinner = dinnerId.flatMap { id in dishes.first { $0.id == id }?.name }
|
||||
let meals: [TodayMealData.Meal] = settings.activeMealTypes.map { mealType in
|
||||
let dishId = plan?.slots.first {
|
||||
$0.dayOfWeek == appDayOfWeek && $0.mealType == mealType.rawValue
|
||||
}?.dishId
|
||||
let name = dishId.flatMap { id in dishes.first { $0.id == id }?.name }
|
||||
return TodayMealData.Meal(
|
||||
type: mealType.rawValue,
|
||||
label: String(localized: String.LocalizationValue(mealType.localizedKey)),
|
||||
name: name
|
||||
)
|
||||
}
|
||||
|
||||
let locale = Locale(identifier: settings.languageEnum.resolved().localeIdentifier)
|
||||
let formatter = DateFormatter()
|
||||
@@ -33,10 +44,7 @@ enum WidgetDataStore {
|
||||
let weekdayName = formatter.string(from: today).capitalized(with: locale)
|
||||
|
||||
let data = TodayMealData(
|
||||
lunch: lunch,
|
||||
dinner: dinner,
|
||||
lunchLabel: String(localized: "lunch"),
|
||||
dinnerLabel: String(localized: "dinner"),
|
||||
meals: meals,
|
||||
weekdayName: weekdayName,
|
||||
updatedAt: today
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user