mirror of
https://github.com/kuhyx/diet-guard.git
synced 2026-11-24 12:26:23 +01:00
Some checks failed
dependency freshness / dependencies on newest stable (push) Has been cancelled
file-length / file length <= 250 lines (push) Has been cancelled
md-naming / markdown naming convention (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (mypy, mypy, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (pylint, pylint, ) (push) Has been cancelled
pre-commit / pre-commit (${{ matrix.group }}) (rest, , mypy,pylint) (push) Has been cancelled
Tests / test (push) Has been cancelled
release-apk / release (APK) (push) Has been cancelled
repo-contract / repo contract (push) Has been cancelled
Fill all with catering always fetched and filled today, so picking 24.10 on 23.10 reported "No catering delivery today." FillAllFlow.tap now takes the picked day: fetch, slot schedule, occupancy and dedup all resolve against it, and logDishes stamps each dish at its slot time on that day. - A plan only confirms onto the day it was proposed for; changing the date (or back to today) disarms it. - A later-day fill leaves today's delivery queue and prefill alone and returns the form to today, as a manual "Log for later" does. - Only today's fetch records the single-day "already fetched" marker; recording a later date would skip that day's automatic fetch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01VwYgigocPkPWa73QZRtU38
106 lines
3.9 KiB
Dart
106 lines
3.9 KiB
Dart
/// Wires "Fill all with catering" into the log form.
|
|
///
|
|
/// Its own file because `log_meal_screen.dart` and
|
|
/// `log_meal_kuchnia_mixin.dart` are both at the repo's 250-line ceiling. The
|
|
/// rule lives in `kuchnia_fill.dart` and the two-tap state in
|
|
/// `kuchnia_fill_flow.dart`; this only connects them to the screen.
|
|
library;
|
|
|
|
import 'package:diet_guard_app/screens/log_meal_future_mixin.dart';
|
|
import 'package:diet_guard_app/screens/log_meal_kuchnia_mixin.dart';
|
|
import 'package:diet_guard_app/screens/log_meal_sync_mixin.dart';
|
|
import 'package:diet_guard_app/services/kuchnia_fill_flow.dart';
|
|
import 'package:diet_guard_app/services/kuchnia_queue.dart';
|
|
import 'package:diet_guard_app/services/kuchnia_spread.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
/// Drives the screen's [FillAllFlow] and tidies the screen after a fill.
|
|
mixin LogMealFillMixin<T extends StatefulWidget>
|
|
on LogMealSyncMixin<T>, LogMealKuchniaMixin<T>, LogMealFutureMixin<T> {
|
|
/// The flow behind the button. Per-screen, so leaving the screen drops an
|
|
/// armed proposal along with it.
|
|
FillAllFlow fillFlow = FillAllFlow();
|
|
|
|
/// Shows [message] in the form's status line. Supplied by the screen.
|
|
void showFillStatus(String message);
|
|
|
|
/// A proposal belongs to the date it was fetched for; picking another (or
|
|
/// going back to today) must not leave "Confirm (N)" offering it.
|
|
@override
|
|
void onLogDateChanged() {
|
|
super.onLogDateChanged();
|
|
fillFlow.cancel();
|
|
}
|
|
|
|
/// Runs one tap: the first proposes, a second on the same day confirms.
|
|
/// Fills the "Log for later" date when one is picked, else today.
|
|
Future<void> onFillAll() async {
|
|
final day = futureDate;
|
|
final pending = fillFlow.tap(day: day);
|
|
setState(() {}); // show the busy label while the fetch/writes run
|
|
final FillOutcome? outcome;
|
|
try {
|
|
outcome = await pending;
|
|
} on Exception catch (error) {
|
|
if (!mounted) return;
|
|
setState(() {});
|
|
// A confirm can fail partway through its writes. Whatever did land is
|
|
// a real meal, so it is published like any other rather than waiting
|
|
// for the next tick, and the user is told the batch did not finish.
|
|
await publishAfterLog();
|
|
await refreshSlots();
|
|
if (mounted) showFillStatus('Fill all failed: $error');
|
|
return;
|
|
}
|
|
if (!mounted) return;
|
|
setState(() {});
|
|
if (outcome == null) return;
|
|
if (outcome.written.isNotEmpty) {
|
|
await _afterFill(outcome.written, later: day != null);
|
|
}
|
|
if (!mounted) return;
|
|
showFillStatus(outcome.message);
|
|
}
|
|
|
|
/// Disarms a proposal without writing anything.
|
|
void onFillCancel() {
|
|
fillFlow.cancel();
|
|
showFillStatus('Fill all cancelled — nothing logged.');
|
|
}
|
|
|
|
/// Publishes the batch once and drops the filled dishes from the delivery
|
|
/// queue, so "Today's delivery (N more to go)" and the prefilled form do
|
|
/// not keep offering meals that were just logged.
|
|
///
|
|
/// A [later] fill logged another day's delivery: today's queue and form are
|
|
/// left alone, and the screen goes back to today, as after a manual
|
|
/// "Log for later" -- the picked day's slot row would otherwise be stale.
|
|
Future<void> _afterFill(
|
|
List<SlottedDish> written, {
|
|
required bool later,
|
|
}) async {
|
|
if (later) {
|
|
resetFutureLog();
|
|
await publishAfterLog();
|
|
await refreshSlots();
|
|
return;
|
|
}
|
|
if (KuchniaQueueService.isInitialized) {
|
|
for (final item in written) {
|
|
KuchniaQueueService.instance.markLogged(item.dish);
|
|
}
|
|
}
|
|
final offered = offeredDish;
|
|
if (offered != null &&
|
|
written.any((item) => item.dish.bankKey == offered.bankKey)) {
|
|
// The prefilled dish was just logged by the fill; leaving it in the
|
|
// form would invite a second, duplicate submit.
|
|
descController.clear();
|
|
macroControllers.clear();
|
|
}
|
|
prefillNextDish();
|
|
await publishAfterLog();
|
|
await refreshSlots();
|
|
}
|
|
}
|