forked from eatvio/eatvio_app
feat(insights): review fixes
This commit is contained in:
@@ -38,6 +38,7 @@ class InsightsCard extends StatelessWidget {
|
||||
this.repository,
|
||||
this.kbjuEnabled = InsightsFeatureFlags.kbjuEnabled,
|
||||
this.refreshToken = 0,
|
||||
this.initialIntraDate,
|
||||
});
|
||||
|
||||
final String? slug;
|
||||
@@ -49,6 +50,10 @@ class InsightsCard extends StatelessWidget {
|
||||
/// в дневнике), сохраняя вкладку, период и выбранный день.
|
||||
final int refreshToken;
|
||||
|
||||
/// День вкладки «В течение дня» при первой загрузке (`YYYY-MM-DD`).
|
||||
/// В дневнике совпадает с открытой датой; `null` — сегодня.
|
||||
final String? initialIntraDate;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return KeyedSubtree(
|
||||
@@ -59,17 +64,24 @@ class InsightsCard extends StatelessWidget {
|
||||
slug: slug,
|
||||
canAdd: canAdd,
|
||||
kbjuEnabled: kbjuEnabled,
|
||||
)..load(),
|
||||
child: _InsightsView(refreshToken: refreshToken),
|
||||
)..load(intraDate: initialIntraDate),
|
||||
child: _InsightsView(
|
||||
refreshToken: refreshToken,
|
||||
initialIntraDate: initialIntraDate,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _InsightsView extends StatefulWidget {
|
||||
const _InsightsView({required this.refreshToken});
|
||||
const _InsightsView({
|
||||
required this.refreshToken,
|
||||
required this.initialIntraDate,
|
||||
});
|
||||
|
||||
final int refreshToken;
|
||||
final String? initialIntraDate;
|
||||
|
||||
@override
|
||||
State<_InsightsView> createState() => _InsightsViewState();
|
||||
@@ -79,8 +91,18 @@ class _InsightsViewState extends State<_InsightsView> {
|
||||
@override
|
||||
void didUpdateWidget(covariant _InsightsView oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
final cubit = context.read<InsightsCubit>();
|
||||
if (oldWidget.refreshToken != widget.refreshToken) {
|
||||
context.read<InsightsCubit>().refresh();
|
||||
cubit.refresh();
|
||||
}
|
||||
final nextDate = widget.initialIntraDate;
|
||||
if (nextDate != null &&
|
||||
nextDate.isNotEmpty &&
|
||||
oldWidget.initialIntraDate != nextDate) {
|
||||
final parsed = DateTime.tryParse(nextDate);
|
||||
if (parsed != null) {
|
||||
cubit.setIntraDate(parsed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user