@@ -3,9 +3,9 @@ import 'dart:async';
3
3
import 'package:collection/collection.dart' ;
4
4
import 'package:fluffychat/config/app_config.dart' ;
5
5
import 'package:fluffychat/pangea/constants/pangea_event_types.dart' ;
6
+ import 'package:fluffychat/pangea/controllers/my_analytics_controller.dart' ;
6
7
import 'package:fluffychat/pangea/controllers/pangea_controller.dart' ;
7
8
import 'package:fluffychat/pangea/enum/construct_type_enum.dart' ;
8
- import 'package:fluffychat/pangea/matrix_event_wrappers/construct_analytics_event.dart' ;
9
9
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_message_event.dart' ;
10
10
import 'package:fluffychat/pangea/matrix_event_wrappers/pangea_representation_event.dart' ;
11
11
import 'package:fluffychat/pangea/models/constructs_analytics_model.dart' ;
@@ -169,7 +169,7 @@ class ConstructListViewState extends State<ConstructListView> {
169
169
170
170
int get lemmaIndex =>
171
171
constructs? .indexWhere (
172
- (element) => element.content. lemma == widget.controller.currentLemma,
172
+ (element) => element.lemma == widget.controller.currentLemma,
173
173
) ??
174
174
- 1 ;
175
175
@@ -217,7 +217,7 @@ class ConstructListViewState extends State<ConstructListView> {
217
217
218
218
setState (() => fetchingUses = true );
219
219
try {
220
- final List <OneConstructUse > uses = currentConstruct! .content. uses;
220
+ final List <OneConstructUse > uses = currentConstruct! .uses;
221
221
_msgEvents.clear ();
222
222
223
223
for (final OneConstructUse use in uses) {
@@ -236,16 +236,24 @@ class ConstructListViewState extends State<ConstructListView> {
236
236
ErrorHandler .logError (
237
237
e: err,
238
238
s: s,
239
- m: "Failed to fetch uses for current construct ${currentConstruct ?.content . lemma }" ,
239
+ m: "Failed to fetch uses for current construct ${currentConstruct ?.lemma }" ,
240
240
);
241
241
}
242
242
}
243
243
244
- List <ConstructEvent >? get constructs =>
245
- widget.pangeaController.analytics.constructs;
246
-
247
- ConstructEvent ? get currentConstruct => constructs? .firstWhereOrNull (
248
- (element) => element.content.lemma == widget.controller.currentLemma,
244
+ List <AggregateConstructUses >? get constructs =>
245
+ widget.pangeaController.analytics.constructs != null
246
+ ? widget.pangeaController.myAnalytics
247
+ .aggregateConstructData (
248
+ widget.pangeaController.analytics.constructs! ,
249
+ )
250
+ .sorted (
251
+ (a, b) => b.uses.length.compareTo (a.uses.length),
252
+ )
253
+ : null ;
254
+
255
+ AggregateConstructUses ? get currentConstruct => constructs? .firstWhereOrNull (
256
+ (element) => element.lemma == widget.controller.currentLemma,
249
257
);
250
258
251
259
// given the current lemma and list of message events, return a list of
@@ -280,6 +288,13 @@ class ConstructListViewState extends State<ConstructListView> {
280
288
return allMsgErrorSteps;
281
289
}
282
290
291
+ Future <void > showConstructMessagesDialog () async {
292
+ await showDialog <ConstructMessagesDialog >(
293
+ context: context,
294
+ builder: (c) => ConstructMessagesDialog (controller: this ),
295
+ );
296
+ }
297
+
283
298
@override
284
299
Widget build (BuildContext context) {
285
300
if (! widget.init || fetchingUses) {
@@ -294,58 +309,92 @@ class ConstructListViewState extends State<ConstructListView> {
294
309
);
295
310
}
296
311
297
- final msgEventMatches = getMessageEventMatches ();
312
+ return Expanded (
313
+ child: ListView .builder (
314
+ itemCount: constructs! .length,
315
+ itemBuilder: (context, index) {
316
+ return ListTile (
317
+ title: Text (
318
+ constructs! [index].lemma,
319
+ ),
320
+ subtitle: Text (
321
+ '${L10n .of (context )!.total } ${constructs ![index ].uses .length }' ,
322
+ ),
323
+ onTap: () async {
324
+ final String lemma = constructs! [index].lemma;
325
+ widget.controller.setCurrentLemma (lemma);
326
+ fetchUses ().then ((_) => showConstructMessagesDialog ());
327
+ },
328
+ );
329
+ },
330
+ ),
331
+ );
332
+ }
333
+ }
298
334
299
- return widget.controller.currentLemma == null
300
- ? Expanded (
301
- child: ListView .builder (
302
- itemCount: constructs! .length,
303
- itemBuilder: (context, index) {
304
- return ListTile (
305
- title: Text (
306
- constructs! [index].content.lemma,
307
- ),
308
- subtitle: Text (
309
- '${L10n .of (context )!.total } ${constructs ![index ].content .uses .length }' ,
310
- ),
311
- onTap: () {
312
- final String lemma = constructs! [index].content.lemma;
313
- widget.controller.setCurrentLemma (lemma);
314
- fetchUses ();
315
- },
316
- );
317
- },
335
+ class ConstructMessagesDialog extends StatelessWidget {
336
+ final ConstructListViewState controller;
337
+ const ConstructMessagesDialog ({
338
+ super .key,
339
+ required this .controller,
340
+ });
341
+
342
+ @override
343
+ Widget build (BuildContext context) {
344
+ if (controller.widget.controller.currentLemma == null ) {
345
+ return const AlertDialog (content: CircularProgressIndicator .adaptive ());
346
+ }
347
+
348
+ final msgEventMatches = controller.getMessageEventMatches ();
349
+
350
+ return AlertDialog (
351
+ title: Center (child: Text (controller.widget.controller.currentLemma! )),
352
+ content: Column (
353
+ mainAxisSize: MainAxisSize .min,
354
+ crossAxisAlignment: CrossAxisAlignment .start,
355
+ children: [
356
+ if (controller.constructs! [controller.lemmaIndex].uses.length >
357
+ controller._msgEvents.length)
358
+ Center (
359
+ child: Padding (
360
+ padding: const EdgeInsets .all (8.0 ),
361
+ child: Text (L10n .of (context)! .roomDataMissing),
362
+ ),
318
363
),
319
- )
320
- : Expanded (
364
+ SingleChildScrollView (
321
365
child: Column (
322
- crossAxisAlignment: CrossAxisAlignment .start,
323
366
children: [
324
- if (constructs! [lemmaIndex].content.uses.length >
325
- _msgEvents.length)
326
- Center (
327
- child: Padding (
328
- padding: const EdgeInsets .all (8.0 ),
329
- child: Text (L10n .of (context)! .roomDataMissing),
330
- ),
331
- ),
332
- Expanded (
333
- child: ListView .separated (
334
- separatorBuilder: (context, index) =>
367
+ ...msgEventMatches.mapIndexed (
368
+ (index, event) => Column (
369
+ children: [
370
+ ConstructMessage (
371
+ msgEvent: event.msgEvent,
372
+ lemma: controller.widget.controller.currentLemma! ,
373
+ errorMessage: event.lemmaMatch,
374
+ ),
375
+ if (index < msgEventMatches.length - 1 )
335
376
const Divider (height: 1 ),
336
- itemCount: msgEventMatches.length,
337
- itemBuilder: (context, index) {
338
- return ConstructMessage (
339
- msgEvent: msgEventMatches[index].msgEvent,
340
- lemma: widget.controller.currentLemma! ,
341
- errorMessage: msgEventMatches[index].lemmaMatch,
342
- );
343
- },
377
+ ],
344
378
),
345
379
),
346
380
],
347
381
),
348
- );
382
+ ),
383
+ ],
384
+ ),
385
+ actions: [
386
+ TextButton (
387
+ onPressed: () => Navigator .of (context, rootNavigator: false ).pop (),
388
+ child: Text (
389
+ L10n .of (context)! .close.toUpperCase (),
390
+ style: TextStyle (
391
+ color:
392
+ Theme .of (context).textTheme.bodyMedium? .color? .withAlpha (150 ),
393
+ ),
394
+ ),
395
+ ),
396
+ ],
397
+ );
349
398
}
350
399
}
351
400
0 commit comments