feat(app): mirror the attention count on the Runs tab
This commit is contained in:
@@ -28,6 +28,7 @@ class NeedsYouRunsHeading extends StatefulWidget {
|
||||
this.now,
|
||||
this.cupertino,
|
||||
this.notifications,
|
||||
this.attention,
|
||||
});
|
||||
|
||||
/// The run summaries the Runs destination already holds.
|
||||
@@ -55,23 +56,36 @@ class NeedsYouRunsHeading extends StatefulWidget {
|
||||
/// the bell, so no store or platform bridge is touched there.
|
||||
final NotificationController? notifications;
|
||||
|
||||
/// The app's shared attention controller, so the shell can mirror the same
|
||||
/// count on the Runs tab. The heading seeds it with [rows]; its owner folds
|
||||
/// [frames] and resets it on reconnect. Absent, the heading owns a private
|
||||
/// controller fed from [frames], which fixtures and the list tests rely on.
|
||||
final AttentionController? attention;
|
||||
|
||||
@override
|
||||
State<NeedsYouRunsHeading> createState() => _NeedsYouRunsHeadingState();
|
||||
}
|
||||
|
||||
class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
||||
late final AttentionController _attention = AttentionController(
|
||||
store: widget.store,
|
||||
now: widget.now,
|
||||
);
|
||||
late final AttentionController _attention =
|
||||
widget.attention ??
|
||||
AttentionController(store: widget.store, now: widget.now);
|
||||
StreamSubscription<JsonMap>? _frames;
|
||||
|
||||
bool get _ownsController => widget.attention == null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_attention.seedRows(widget.rows);
|
||||
unawaited(_attention.load());
|
||||
_listen();
|
||||
if (_ownsController) {
|
||||
unawaited(_attention.load());
|
||||
_listen();
|
||||
} else {
|
||||
// The owner folds frames; publishing after every change it makes is the
|
||||
// same idempotent call the private path makes after each frame.
|
||||
_attention.addListener(_publish);
|
||||
}
|
||||
final notifications = widget.notifications;
|
||||
if (notifications != null) {
|
||||
notifications.onOpenRun = _openRunById;
|
||||
@@ -115,7 +129,7 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
||||
@override
|
||||
void didUpdateWidget(covariant NeedsYouRunsHeading oldWidget) {
|
||||
super.didUpdateWidget(oldWidget);
|
||||
if (!identical(oldWidget.frames, widget.frames)) {
|
||||
if (_ownsController && !identical(oldWidget.frames, widget.frames)) {
|
||||
unawaited(_frames?.cancel());
|
||||
_frames = null;
|
||||
_listen();
|
||||
@@ -135,7 +149,11 @@ class _NeedsYouRunsHeadingState extends State<NeedsYouRunsHeading> {
|
||||
@override
|
||||
void dispose() {
|
||||
unawaited(_frames?.cancel());
|
||||
_attention.dispose();
|
||||
if (_ownsController) {
|
||||
_attention.dispose();
|
||||
} else {
|
||||
_attention.removeListener(_publish);
|
||||
}
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/widgets.dart';
|
||||
import '../../core/api_gateway.dart';
|
||||
import '../../ui/adaptive/host.dart';
|
||||
import '../attention/notify/notification_controller.dart';
|
||||
import '../attention/runtime/attention_controller.dart';
|
||||
import '../attention/runtime/attention_store.dart';
|
||||
import 'actions/decision_action.dart';
|
||||
import 'data/runs_repository.dart';
|
||||
@@ -34,6 +35,7 @@ class RunsScreen extends StatefulWidget {
|
||||
this.attentionStore = const SharedPreferencesAttentionStore(),
|
||||
this.attentionNow,
|
||||
this.notifications,
|
||||
this.attention,
|
||||
});
|
||||
|
||||
final ApiGateway gateway;
|
||||
@@ -70,6 +72,9 @@ class RunsScreen extends StatefulWidget {
|
||||
/// App-level notification delivery for live attention transitions.
|
||||
final NotificationController? notifications;
|
||||
|
||||
/// The app's shared attention controller, mirrored on the shell's Runs tab.
|
||||
final AttentionController? attention;
|
||||
|
||||
@override
|
||||
State<RunsScreen> createState() => _RunsScreenState();
|
||||
}
|
||||
@@ -193,6 +198,7 @@ class _RunsScreenState extends State<RunsScreen> {
|
||||
attentionStore: widget.attentionStore,
|
||||
attentionNow: widget.attentionNow,
|
||||
notifications: widget.notifications,
|
||||
attention: widget.attention,
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
@@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../attention/notify/notification_controller.dart';
|
||||
import '../../attention/runtime/attention_controller.dart';
|
||||
import '../../attention/runtime/attention_store.dart';
|
||||
import '../../attention/ui/needs_you_runs_heading.dart';
|
||||
import '../domain/run_models.dart';
|
||||
@@ -19,6 +20,7 @@ class RunsList extends StatelessWidget {
|
||||
this.attentionStore = const SharedPreferencesAttentionStore(),
|
||||
this.attentionNow,
|
||||
this.notifications,
|
||||
this.attention,
|
||||
});
|
||||
|
||||
final RunsController controller;
|
||||
@@ -37,6 +39,9 @@ class RunsList extends StatelessWidget {
|
||||
/// App-level notification delivery; absent in list-only fixtures.
|
||||
final NotificationController? notifications;
|
||||
|
||||
/// The app's shared attention controller; absent in list-only fixtures.
|
||||
final AttentionController? attention;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
if (controller.loading && controller.runs.isEmpty) {
|
||||
@@ -108,6 +113,7 @@ class RunsList extends StatelessWidget {
|
||||
store: attentionStore,
|
||||
now: attentionNow,
|
||||
notifications: notifications,
|
||||
attention: attention,
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user