chore: update analytics page on construct update (#4987)

This commit is contained in:
ggurdin 2025-12-30 13:42:51 -05:00 committed by GitHub
parent 9a36662083
commit 0dbbba5a27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -42,33 +42,48 @@ class ConstructAnalyticsViewState extends State<ConstructAnalyticsView> {
bool isSearching = false;
ConstructLevelEnum? selectedConstructLevel;
StreamSubscription<AnalyticsStreamUpdate>? _blockedConstructSub;
StreamSubscription<AnalyticsStreamUpdate>? _constructUpdateSub;
@override
void initState() {
super.initState();
_setMorphs();
_setVocab();
_setAnalyticsData();
searchController.addListener(() {
if (mounted) setState(() {});
});
_blockedConstructSub = Matrix.of(context)
_constructUpdateSub = Matrix.of(context)
.analyticsDataService
.updateDispatcher
.constructUpdateStream
.stream
.listen(_onBlockConstruct);
.listen(_onConstructUpdate);
}
@override
void dispose() {
searchController.dispose();
_blockedConstructSub?.cancel();
_constructUpdateSub?.cancel();
super.dispose();
}
Future<void> _setAnalyticsData() async {
final future = <Future>[
_setMorphs(),
_setVocab(),
];
await Future.wait(future);
}
void _onConstructUpdate(AnalyticsStreamUpdate update) {
if (update.blockedConstruct != null) {
_onBlockConstruct(update);
}
_setAnalyticsData();
}
void _onBlockConstruct(AnalyticsStreamUpdate update) {
final blocked = update.blockedConstruct;
if (blocked == null) return;