feat(app): offline-кэш на остальных экранах — фаза 5
accounts, cashflow, categories, goals, income, portfolio (+instrument), rebalance, tax, rules переведены на Cached<T> по контракту docs/ai/offline-cache.md. Общие/второстепенные селекторы (scopesProvider, categoriesListProvider и т.п.) оставлены как есть — не основной контент экрана. sync_page.dart и settings_page.dart не тронуты (первый — заменён health-page отдельно, второй — чистые действия без списка для баннера).
This commit is contained in:
@@ -2,19 +2,23 @@ import 'package:fintracker_api/fintracker_api.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../core/api/api_client.dart';
|
||||
import '../../core/cache/cached.dart';
|
||||
|
||||
final rulesListProvider = FutureProvider.autoDispose<List<RuleOut>>((ref) async {
|
||||
/// See `docs/ai/offline-cache.md`.
|
||||
final rulesListProvider = FutureProvider.autoDispose<Cached<List<RuleOut>>>((ref) async {
|
||||
final r = await ref.watch(apiProvider).getRulesApi().rulesList();
|
||||
return r.data ?? const [];
|
||||
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
|
||||
});
|
||||
|
||||
/// Enabled rules that matched nothing in the latest refresh.
|
||||
final rulesStaleProvider = FutureProvider.autoDispose<List<RuleOut>>((ref) async {
|
||||
/// Enabled rules that matched nothing in the latest refresh — «устарело» here is a business
|
||||
/// concept (the rule looks dead), unrelated to the offline-cache staleness this file also
|
||||
/// tracks; both happen to be named "stale" in their own domains.
|
||||
final rulesStaleProvider = FutureProvider.autoDispose<Cached<List<RuleOut>>>((ref) async {
|
||||
final r = await ref.watch(apiProvider).getRulesApi().rulesStale();
|
||||
return r.data ?? const [];
|
||||
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
|
||||
});
|
||||
|
||||
final staleRuleIdsProvider = Provider.autoDispose<Set<int>>((ref) {
|
||||
final stale = ref.watch(rulesStaleProvider).valueOrNull ?? const [];
|
||||
final stale = ref.watch(rulesStaleProvider).valueOrNull?.data ?? const [];
|
||||
return {for (final r in stale) r.id};
|
||||
});
|
||||
|
||||
@@ -5,9 +5,11 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../core/api/api_client.dart';
|
||||
import '../../core/auth/auth_controller.dart';
|
||||
import '../../core/cache/cached.dart';
|
||||
import '../../core/utils/ru_date.dart';
|
||||
import '../../core/widgets/async_value_view.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../core/widgets/stale_banner.dart';
|
||||
import 'providers.dart';
|
||||
|
||||
String ruleKindLabel(RuleKind k) => switch (k) {
|
||||
@@ -77,6 +79,10 @@ class RulesPage extends ConsumerWidget {
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final rules = ref.watch(rulesListProvider);
|
||||
final staleIds = ref.watch(staleRuleIdsProvider);
|
||||
final stale = oldestFetch([
|
||||
rules.valueOrNull?.fetchedAt,
|
||||
ref.watch(rulesStaleProvider).valueOrNull?.fetchedAt,
|
||||
]);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -101,11 +107,13 @@ class RulesPage extends ConsumerWidget {
|
||||
child: AsyncValueView(
|
||||
value: rules,
|
||||
onRetry: () => ref.invalidate(rulesListProvider),
|
||||
data: (rows) {
|
||||
data: (cached) {
|
||||
final rows = cached.data;
|
||||
if (rows.isEmpty) {
|
||||
return ListView(
|
||||
children: const [
|
||||
EmptyState(icon: Icons.rule_folder_outlined, message: 'Правил ещё нет.'),
|
||||
children: [
|
||||
if (stale != null) StaleBanner(fetchedAt: stale),
|
||||
const EmptyState(icon: Icons.rule_folder_outlined, message: 'Правил ещё нет.'),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -113,6 +121,7 @@ class RulesPage extends ConsumerWidget {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
if (stale != null) StaleBanner(fetchedAt: stale),
|
||||
for (final rule in sorted)
|
||||
_RuleTile(
|
||||
rule: rule,
|
||||
|
||||
Reference in New Issue
Block a user