fix: fix menu generation errors and show planned meals on home screen
Backend fixes: - migration 003: add 'menu' value to recipe_source enum (was causing SQLSTATE 22P02) - migration 004: rename recipe_products→recipe_ingredients, product_id→ingredient_id (was causing SQLSTATE 42P01) - dish/repository.go: fix INSERT INTO tags using $1/$1 for two columns → $1/$2 (was causing SQLSTATE 42P08) - home/handler.go: replace non-existent saved_recipes table with correct joins (recipes→dishes→dish_translations, user_saved_recipes) so today's plan and recommendations load correctly - reqlog: new slog.Handler wrapper that adds request_id and stack trace to ERROR-level logs - all handlers: slog.Error→slog.ErrorContext so error logs include request context; writeError includes request_id in response body Client: - home_screen.dart: extend home screen to future dates, show planned meals as ghost entries - l10n: add new localisation keys for home screen date navigation and planned meal UI Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -96,7 +96,7 @@ class HomeScreen extends ConsumerWidget {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
if (isFutureDate)
|
||||
_PlanningBanner(dateString: dateString)
|
||||
_FutureDayHeader(dateString: dateString)
|
||||
else ...[
|
||||
_CaloriesCard(
|
||||
loggedCalories: loggedCalories,
|
||||
@@ -1143,6 +1143,163 @@ class _DiaryEntryTile extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// ── Future day header (wraps banner + menu-gen CTA) ────────────
|
||||
|
||||
class _FutureDayHeader extends ConsumerWidget {
|
||||
final String dateString;
|
||||
const _FutureDayHeader({required this.dateString});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final l10n = AppLocalizations.of(context)!;
|
||||
final date = DateTime.parse(dateString);
|
||||
final weekString = isoWeekString(date);
|
||||
final menuState = ref.watch(menuProvider(weekString));
|
||||
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
_PlanningBanner(dateString: dateString),
|
||||
const SizedBox(height: 8),
|
||||
menuState.when(
|
||||
loading: () => _GenerateLoadingCard(l10n: l10n),
|
||||
error: (_, __) => _GenerateActionCard(
|
||||
l10n: l10n,
|
||||
onGenerate: () =>
|
||||
ref.read(menuProvider(weekString).notifier).generate(),
|
||||
),
|
||||
data: (plan) => plan == null
|
||||
? _GenerateActionCard(
|
||||
l10n: l10n,
|
||||
onGenerate: () =>
|
||||
ref.read(menuProvider(weekString).notifier).generate(),
|
||||
)
|
||||
: _WeekPlannedChip(l10n: l10n),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _GenerateActionCard extends StatelessWidget {
|
||||
final AppLocalizations l10n;
|
||||
final VoidCallback onGenerate;
|
||||
const _GenerateActionCard({required this.l10n, required this.onGenerate});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(16),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
children: [
|
||||
Icon(Icons.auto_awesome,
|
||||
color: theme.colorScheme.primary, size: 20),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
l10n.generateWeekLabel,
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
color: theme.colorScheme.onSurface,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
l10n.generateWeekSubtitle,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
FilledButton(
|
||||
onPressed: onGenerate,
|
||||
child: Text(l10n.generateWeekLabel),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _GenerateLoadingCard extends StatelessWidget {
|
||||
final AppLocalizations l10n;
|
||||
const _GenerateLoadingCard({required this.l10n});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 14),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.surfaceContainerLow,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 18,
|
||||
height: 18,
|
||||
child: CircularProgressIndicator.adaptive(
|
||||
strokeWidth: 2,
|
||||
valueColor: AlwaysStoppedAnimation(theme.colorScheme.primary),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Text(
|
||||
l10n.generatingMenu,
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: theme.colorScheme.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _WeekPlannedChip extends StatelessWidget {
|
||||
final AppLocalizations l10n;
|
||||
const _WeekPlannedChip({required this.l10n});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
return Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
decoration: BoxDecoration(
|
||||
color: theme.colorScheme.secondaryContainer,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(Icons.check_circle_outline,
|
||||
color: theme.colorScheme.onSecondaryContainer, size: 18),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
l10n.weekPlannedLabel,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.colorScheme.onSecondaryContainer,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Planning banner (future dates) ────────────────────────────
|
||||
|
||||
class _PlanningBanner extends StatelessWidget {
|
||||
|
||||
Reference in New Issue
Block a user