From 4e8f9abfb096796dd7bd11275df263ae09b2883e Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 29 May 2024 12:10:36 -0400 Subject: [PATCH 1/2] sort errors by number, prevent horizontal scrolling of analytics tab, join chat on analytics tile click --- .../pages/analytics/analytics_list_tile.dart | 1 - .../pages/analytics/base_analytics.dart | 25 ++++++++++++++++++- .../pages/analytics/base_analytics_view.dart | 1 + .../pages/analytics/construct_list.dart | 10 +++++--- 4 files changed, 32 insertions(+), 5 deletions(-) diff --git a/lib/pangea/pages/analytics/analytics_list_tile.dart b/lib/pangea/pages/analytics/analytics_list_tile.dart index ab35b26104..811f02f6f6 100644 --- a/lib/pangea/pages/analytics/analytics_list_tile.dart +++ b/lib/pangea/pages/analytics/analytics_list_tile.dart @@ -104,7 +104,6 @@ class AnalyticsListTileState extends State { ) : null, selected: widget.selected, - enabled: widget.enabled, onTap: () { (room?.isSpace ?? false) && widget.allowNavigateOnSelect ? context.go( diff --git a/lib/pangea/pages/analytics/base_analytics.dart b/lib/pangea/pages/analytics/base_analytics.dart index 634a399805..55731cfb3d 100644 --- a/lib/pangea/pages/analytics/base_analytics.dart +++ b/lib/pangea/pages/analytics/base_analytics.dart @@ -5,6 +5,7 @@ import 'package:fluffychat/pangea/extensions/client_extension.dart'; import 'package:fluffychat/pangea/pages/analytics/base_analytics_view.dart'; import 'package:fluffychat/pangea/pages/analytics/student_analytics/student_analytics.dart'; import 'package:flutter/material.dart'; +import 'package:future_loading_dialog/future_loading_dialog.dart'; import 'package:matrix/matrix.dart'; import '../../../widgets/matrix.dart'; @@ -101,18 +102,40 @@ class BaseAnalyticsController extends State { } } - void toggleSelection(AnalyticsSelected selectedParam) { + Future toggleSelection(AnalyticsSelected selectedParam) async { + final bool joinSelectedRoom = + selectedParam.type == AnalyticsEntryType.room && + !enableSelection( + selectedParam, + ); + + if (joinSelectedRoom) { + await showFutureLoadingDialog( + context: context, + future: () async { + final waitForRoom = Matrix.of(context).client.waitForRoomInSync( + selectedParam.id, + join: true, + ); + await Matrix.of(context).client.joinRoom(selectedParam.id); + await waitForRoom; + }, + ); + } + setState(() { debugPrint("selectedParam.id is ${selectedParam.id}"); currentLemma = null; selected = isSelected(selectedParam.id) ? null : selectedParam; }); + pangeaController.analytics.setConstructs( constructType: ConstructType.grammar, defaultSelected: widget.defaultSelected, selected: selected, removeIT: true, ); + Future.delayed(Duration.zero, () => setState(() {})); } diff --git a/lib/pangea/pages/analytics/base_analytics_view.dart b/lib/pangea/pages/analytics/base_analytics_view.dart index 86f179829b..0c9bf3bc4f 100644 --- a/lib/pangea/pages/analytics/base_analytics_view.dart +++ b/lib/pangea/pages/analytics/base_analytics_view.dart @@ -145,6 +145,7 @@ class BaseAnalyticsView extends StatelessWidget { ) * 72, child: TabBarView( + physics: const NeverScrollableScrollPhysics(), children: [ Column( crossAxisAlignment: diff --git a/lib/pangea/pages/analytics/construct_list.dart b/lib/pangea/pages/analytics/construct_list.dart index ca48d4d921..508a1bc7e1 100644 --- a/lib/pangea/pages/analytics/construct_list.dart +++ b/lib/pangea/pages/analytics/construct_list.dart @@ -243,9 +243,13 @@ class ConstructListViewState extends State { List? get constructs => widget.pangeaController.analytics.constructs != null - ? widget.pangeaController.myAnalytics.aggregateConstructData( - widget.pangeaController.analytics.constructs!, - ) + ? widget.pangeaController.myAnalytics + .aggregateConstructData( + widget.pangeaController.analytics.constructs!, + ) + .sorted( + (a, b) => b.uses.length.compareTo(a.uses.length), + ) : null; AggregateConstructUses? get currentConstruct => constructs?.firstWhereOrNull( From 38cf8531ba5a64a0c3a548fc9a9c150166ff5e7c Mon Sep 17 00:00:00 2001 From: ggurdin Date: Wed, 29 May 2024 12:36:09 -0400 Subject: [PATCH 2/2] change message error list into dialog --- .../pages/analytics/construct_list.dart | 126 ++++++++++++------ 1 file changed, 84 insertions(+), 42 deletions(-) diff --git a/lib/pangea/pages/analytics/construct_list.dart b/lib/pangea/pages/analytics/construct_list.dart index 508a1bc7e1..f050222ec3 100644 --- a/lib/pangea/pages/analytics/construct_list.dart +++ b/lib/pangea/pages/analytics/construct_list.dart @@ -288,6 +288,13 @@ class ConstructListViewState extends State { return allMsgErrorSteps; } + Future showConstructMessagesDialog() async { + await showDialog( + context: context, + builder: (c) => ConstructMessagesDialog(controller: this), + ); + } + @override Widget build(BuildContext context) { if (!widget.init || fetchingUses) { @@ -302,57 +309,92 @@ class ConstructListViewState extends State { ); } - final msgEventMatches = getMessageEventMatches(); + return Expanded( + child: ListView.builder( + itemCount: constructs!.length, + itemBuilder: (context, index) { + return ListTile( + title: Text( + constructs![index].lemma, + ), + subtitle: Text( + '${L10n.of(context)!.total} ${constructs![index].uses.length}', + ), + onTap: () async { + final String lemma = constructs![index].lemma; + widget.controller.setCurrentLemma(lemma); + fetchUses().then((_) => showConstructMessagesDialog()); + }, + ); + }, + ), + ); + } +} - return widget.controller.currentLemma == null - ? Expanded( - child: ListView.builder( - itemCount: constructs!.length, - itemBuilder: (context, index) { - return ListTile( - title: Text( - constructs![index].lemma, - ), - subtitle: Text( - '${L10n.of(context)!.total} ${constructs![index].uses.length}', - ), - onTap: () { - final String lemma = constructs![index].lemma; - widget.controller.setCurrentLemma(lemma); - fetchUses(); - }, - ); - }, +class ConstructMessagesDialog extends StatelessWidget { + final ConstructListViewState controller; + const ConstructMessagesDialog({ + super.key, + required this.controller, + }); + + @override + Widget build(BuildContext context) { + if (controller.widget.controller.currentLemma == null) { + return const AlertDialog(content: CircularProgressIndicator.adaptive()); + } + + final msgEventMatches = controller.getMessageEventMatches(); + + return AlertDialog( + title: Center(child: Text(controller.widget.controller.currentLemma!)), + content: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + if (controller.constructs![controller.lemmaIndex].uses.length > + controller._msgEvents.length) + Center( + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Text(L10n.of(context)!.roomDataMissing), + ), ), - ) - : Expanded( + SingleChildScrollView( child: Column( - crossAxisAlignment: CrossAxisAlignment.start, children: [ - if (constructs![lemmaIndex].uses.length > _msgEvents.length) - Center( - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text(L10n.of(context)!.roomDataMissing), - ), - ), - Expanded( - child: ListView.separated( - separatorBuilder: (context, index) => + ...msgEventMatches.mapIndexed( + (index, event) => Column( + children: [ + ConstructMessage( + msgEvent: event.msgEvent, + lemma: controller.widget.controller.currentLemma!, + errorMessage: event.lemmaMatch, + ), + if (index < msgEventMatches.length - 1) const Divider(height: 1), - itemCount: msgEventMatches.length, - itemBuilder: (context, index) { - return ConstructMessage( - msgEvent: msgEventMatches[index].msgEvent, - lemma: widget.controller.currentLemma!, - errorMessage: msgEventMatches[index].lemmaMatch, - ); - }, + ], ), ), ], ), - ); + ), + ], + ), + actions: [ + TextButton( + onPressed: () => Navigator.of(context, rootNavigator: false).pop(), + child: Text( + L10n.of(context)!.close.toUpperCase(), + style: TextStyle( + color: + Theme.of(context).textTheme.bodyMedium?.color?.withAlpha(150), + ), + ), + ), + ], + ); } }