feat: flexible meal planning wizard — plan 1 meal, 1 day, several days, or a week
Backend:
- migration 005: expand menu_items.meal_type CHECK to all 6 types (second_breakfast, afternoon_snack, snack)
- ai/types.go: add Days and MealTypes to MenuRequest for partial generation
- openai/menu.go: parametrize GenerateMenu — use requested meal types and day count; add caloric fractions for all 6 meal types
- menu/repository.go: add UpsertItemsInTx for partial upsert (preserves existing slots); fix meal_type sort order in GetByWeek
- menu/handler.go: add dates+meal_types path to POST /ai/generate-menu; extract fetchImages/saveRecipes helpers; returns {"plans":[...]} for dates mode; backward-compatible with week mode
Client:
- PlanMenuSheet: bottom sheet with 4 planning horizon options
- PlanDatePickerSheet: adaptive sheet with date strip (single day/meal) or custom CalendarRangePicker (multi-day/week); sliding 7-day window for week mode
- menu_service.dart: add generateForDates
- menu_provider.dart: add PlanMenuService (generates + invalidates week providers), lastPlannedDateProvider
- home_screen.dart: add _PlanMenuButton card below quick actions; opens planning wizard
- l10n: 16 new keys for planning UI across all 12 languages
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -151,3 +151,54 @@ final diaryProvider =
|
||||
StateNotifierProvider.family<DiaryNotifier, AsyncValue<List<DiaryEntry>>, String>(
|
||||
(ref, date) => DiaryNotifier(ref.read(menuServiceProvider), date),
|
||||
);
|
||||
|
||||
// ── Plan menu helpers ─────────────────────────────────────────
|
||||
|
||||
/// The latest future date (among cached menus for the current and next two weeks)
|
||||
/// that already has at least one planned meal slot. Returns null when no future
|
||||
/// meals are planned.
|
||||
final lastPlannedDateProvider = Provider<DateTime?>((ref) {
|
||||
final today = DateTime.now();
|
||||
DateTime? latestDate;
|
||||
for (var offsetDays = 0; offsetDays <= 14; offsetDays += 7) {
|
||||
final weekDate = today.add(Duration(days: offsetDays));
|
||||
final plan = ref.watch(menuProvider(isoWeekString(weekDate))).valueOrNull;
|
||||
if (plan == null) continue;
|
||||
for (final day in plan.days) {
|
||||
final dayDate = DateTime.parse(day.date);
|
||||
if (dayDate.isAfter(today) && day.meals.isNotEmpty) {
|
||||
if (latestDate == null || dayDate.isAfter(latestDate)) {
|
||||
latestDate = dayDate;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return latestDate;
|
||||
});
|
||||
|
||||
/// Service for planning meals across specific dates.
|
||||
/// Calls the API and then invalidates the affected week providers so that
|
||||
/// [plannedMealsProvider] picks up the new slots automatically.
|
||||
class PlanMenuService {
|
||||
final Ref _ref;
|
||||
|
||||
const PlanMenuService(this._ref);
|
||||
|
||||
Future<void> generateForDates({
|
||||
required List<String> dates,
|
||||
required List<String> mealTypes,
|
||||
}) async {
|
||||
final menuService = _ref.read(menuServiceProvider);
|
||||
final plans = await menuService.generateForDates(
|
||||
dates: dates,
|
||||
mealTypes: mealTypes,
|
||||
);
|
||||
for (final plan in plans) {
|
||||
_ref.invalidate(menuProvider(isoWeekString(DateTime.parse(plan.weekStart))));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final planMenuServiceProvider = Provider<PlanMenuService>((ref) {
|
||||
return PlanMenuService(ref);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user