Backend: - Rename recognition_jobs → dish_recognition_jobs; add target_date and target_meal_type columns to capture scan context at submission time - Add job_id FK on meal_diary so entries are linked to their origin job - New GET /ai/jobs endpoint returns today's unlinked jobs for the current user - diary.Entry and CreateRequest gain job_id field; repository reads/writes it - CORS middleware: allow Accept-Language and Cache-Control headers - Logging middleware: implement http.Flusher on responseWriter (needed for SSE) - Consolidate migrations into a single 001_initial_schema.sql Flutter: - POST /ai/recognize-dish now sends target_date and target_meal_type - DishResultSheet accepts jobId; _addToDiary includes it in the diary payload, saves last-used meal type to SharedPreferences, invalidates todayJobsProvider - TodayJobsNotifier + todayJobsProvider: loads unlinked jobs via GET /ai/jobs - Home screen shows _TodayJobsWidget (up to 3 tiles) between macros and meals; tapping a done tile reopens DishResultSheet with the stored result - Quick Actions row: third button "История" → /scan/history - New RecognitionHistoryScreen: full-screen list of today's unlinked jobs - LocalPreferences wrapper over SharedPreferences (last_used_meal_type) - app_theme: apply Google Fonts Roboto as default font family Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
59 lines
2.0 KiB
Dart
59 lines
2.0 KiB
Dart
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
|
|
|
import '../../features/scan/recognition_service.dart';
|
|
import '../../shared/models/home_summary.dart';
|
|
import 'home_service.dart';
|
|
|
|
// ── Selected date (persists while app is open) ────────────────
|
|
|
|
/// The date currently viewed on the home screen.
|
|
/// Defaults to today; can be changed via the date selector.
|
|
final selectedDateProvider = StateProvider<DateTime>((ref) => DateTime.now());
|
|
|
|
/// Formats a [DateTime] to the 'YYYY-MM-DD' string expected by the diary API.
|
|
String formatDateForDiary(DateTime date) =>
|
|
'${date.year}-${date.month.toString().padLeft(2, '0')}-'
|
|
'${date.day.toString().padLeft(2, '0')}';
|
|
|
|
// ── Home summary ──────────────────────────────────────────────
|
|
|
|
class HomeNotifier extends StateNotifier<AsyncValue<HomeSummary>> {
|
|
final HomeService _service;
|
|
|
|
HomeNotifier(this._service) : super(const AsyncValue.loading()) {
|
|
load();
|
|
}
|
|
|
|
Future<void> load() async {
|
|
state = const AsyncValue.loading();
|
|
state = await AsyncValue.guard(() => _service.getSummary());
|
|
}
|
|
}
|
|
|
|
final homeProvider =
|
|
StateNotifierProvider<HomeNotifier, AsyncValue<HomeSummary>>(
|
|
(ref) => HomeNotifier(ref.read(homeServiceProvider)),
|
|
);
|
|
|
|
// ── Today's unlinked recognition jobs ─────────────────────────
|
|
|
|
class TodayJobsNotifier
|
|
extends StateNotifier<AsyncValue<List<DishJobSummary>>> {
|
|
final RecognitionService _service;
|
|
|
|
TodayJobsNotifier(this._service) : super(const AsyncValue.loading()) {
|
|
load();
|
|
}
|
|
|
|
Future<void> load() async {
|
|
state = const AsyncValue.loading();
|
|
state =
|
|
await AsyncValue.guard(() => _service.listTodayUnlinkedJobs());
|
|
}
|
|
}
|
|
|
|
final todayJobsProvider =
|
|
StateNotifierProvider<TodayJobsNotifier, AsyncValue<List<DishJobSummary>>>(
|
|
(ref) => TodayJobsNotifier(ref.read(recognitionServiceProvider)),
|
|
);
|