From 6618fdeb4619d65290ab328b27f645a817743e6c Mon Sep 17 00:00:00 2001 From: ggurdin <46800240+ggurdin@users.noreply.github.com> Date: Wed, 26 Feb 2025 11:06:28 -0500 Subject: [PATCH] chore: move learning settings button to fix overflow in analytics summary (#1929) --- .../learning_progress_indicators.dart | 68 +++++++------ .../learning_settings_button.dart | 56 +++++------ .../analytics_summary/progress_indicator.dart | 95 +++++++++---------- 3 files changed, 115 insertions(+), 104 deletions(-) diff --git a/lib/pangea/analytics_summary/learning_progress_indicators.dart b/lib/pangea/analytics_summary/learning_progress_indicators.dart index ed83a22ca..728ce1a21 100644 --- a/lib/pangea/analytics_summary/learning_progress_indicators.dart +++ b/lib/pangea/analytics_summary/learning_progress_indicators.dart @@ -3,6 +3,7 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/l10n.dart'; +import 'package:matrix/matrix.dart'; import 'package:fluffychat/pages/chat_list/client_chooser_button.dart'; import 'package:fluffychat/pangea/analytics_details_popup/analytics_details_popup.dart'; @@ -38,6 +39,7 @@ class LearningProgressIndicatorsState StreamSubscription? _analyticsSubscription; StreamSubscription? _languageSubscription; + Profile? _profile; @override void initState() { @@ -57,6 +59,12 @@ class LearningProgressIndicatorsState MatrixState.pangeaController.userController.stateStream.listen((_) { if (mounted) setState(() {}); }); + + final client = MatrixState.pangeaController.matrixState.client; + if (client.userID == null) return; + client.getProfileFromUserId(client.userID!).then((profile) { + if (mounted) setState(() => _profile = profile); + }); } @override @@ -92,6 +100,9 @@ class LearningProgressIndicatorsState final userL2 = MatrixState.pangeaController.languageController.userL2; + final mxid = Matrix.of(context).client.userID ?? L10n.of(context).user; + final displayname = _profile?.displayName ?? mxid.localpart ?? mxid; + return Row( children: [ const ClientChooserButton(), @@ -100,17 +111,18 @@ class LearningProgressIndicatorsState child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - Matrix.of(context).client.userID ?? L10n.of(context).user, - style: TextStyle( - color: Theme.of(context).colorScheme.primary, - fontSize: 12, - ), - ), - const SizedBox(height: 6), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, + spacing: 6.0, children: [ + Text( + displayname, + style: TextStyle( + fontSize: 14, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, + ), + ), LearningSettingsButton( onTap: () => showDialog( context: context, @@ -118,28 +130,30 @@ class LearningProgressIndicatorsState ), l2: userL2?.langCode.toUpperCase(), ), - Row( - children: ConstructTypeEnum.values - .map( - (c) => ProgressIndicatorBadge( - points: uniqueLemmas(c.indicator), - loading: _loading, - onTap: () { - showDialog( - context: context, - builder: (context) => AnalyticsPopupWrapper( - view: c, - ), - ); - }, - indicator: c.indicator, - ), - ) - .toList(), - ), ], ), const SizedBox(height: 6), + Row( + spacing: 6.0, + children: ConstructTypeEnum.values + .map( + (c) => ProgressIndicatorBadge( + points: uniqueLemmas(c.indicator), + loading: _loading, + onTap: () { + showDialog( + context: context, + builder: (context) => AnalyticsPopupWrapper( + view: c, + ), + ); + }, + indicator: c.indicator, + ), + ) + .toList(), + ), + const SizedBox(height: 6), MouseRegion( cursor: SystemMouseCursors.click, child: GestureDetector( diff --git a/lib/pangea/analytics_summary/learning_settings_button.dart b/lib/pangea/analytics_summary/learning_settings_button.dart index 8c2870bad..4bc119b2c 100644 --- a/lib/pangea/analytics_summary/learning_settings_button.dart +++ b/lib/pangea/analytics_summary/learning_settings_button.dart @@ -17,41 +17,41 @@ class LearningSettingsButton extends StatelessWidget { @override Widget build(BuildContext context) { - return Tooltip( - message: L10n.of(context).learningSettings, - child: PressableButton( - buttonHeight: 2.5, - borderRadius: BorderRadius.circular(15), - onPressed: onTap, - color: Theme.of(context).colorScheme.surfaceBright, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15), - color: Theme.of(context).colorScheme.surfaceBright, + return Row( + mainAxisSize: MainAxisSize.min, + spacing: 4.0, + children: [ + Text( + l2 ?? "?", + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.bold, + color: Theme.of(context).colorScheme.primary, ), - padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Icon( + ), + Tooltip( + message: L10n.of(context).learningSettings, + child: PressableButton( + buttonHeight: 2.5, + borderRadius: BorderRadius.circular(15), + onPressed: onTap, + color: Theme.of(context).colorScheme.surfaceBright, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: Theme.of(context).colorScheme.surfaceBright, + ), + padding: const EdgeInsets.all(4.0), + child: Icon( size: 14, - Icons.language, + Icons.settings_outlined, color: Theme.of(context).colorScheme.primary, weight: 1000, ), - const SizedBox(width: 5), - Text( - l2 ?? "?", - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.bold, - color: Theme.of(context).colorScheme.primary, - ), - ), - ], + ), ), ), - ), + ], ); } } diff --git a/lib/pangea/analytics_summary/progress_indicator.dart b/lib/pangea/analytics_summary/progress_indicator.dart index 262a25631..faaaa46b6 100644 --- a/lib/pangea/analytics_summary/progress_indicator.dart +++ b/lib/pangea/analytics_summary/progress_indicator.dart @@ -20,58 +20,55 @@ class ProgressIndicatorBadge extends StatelessWidget { @override Widget build(BuildContext context) { - return Padding( - padding: const EdgeInsets.only(left: 6), - child: Tooltip( - message: indicator.tooltip(context), - child: PressableButton( - color: Theme.of(context).colorScheme.surfaceBright, - borderRadius: BorderRadius.circular(15), - onPressed: onTap, - buttonHeight: 2.5, - child: Container( - decoration: BoxDecoration( - borderRadius: BorderRadius.circular(15), - color: Theme.of(context).colorScheme.surfaceBright, - ), - padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Icon( - size: 14, - indicator.icon, + return Tooltip( + message: indicator.tooltip(context), + child: PressableButton( + color: Theme.of(context).colorScheme.surfaceBright, + borderRadius: BorderRadius.circular(15), + onPressed: onTap, + buttonHeight: 2.5, + child: Container( + decoration: BoxDecoration( + borderRadius: BorderRadius.circular(15), + color: Theme.of(context).colorScheme.surfaceBright, + ), + padding: const EdgeInsets.symmetric(horizontal: 6, vertical: 2), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon( + size: 14, + indicator.icon, + color: indicator.color(context), + weight: 1000, + ), + const SizedBox(width: 4.0), + Text( + indicator.tooltip(context), + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.bold, color: indicator.color(context), - weight: 1000, ), - const SizedBox(width: 4.0), - Text( - indicator.tooltip(context), - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.bold, - color: indicator.color(context), - ), - ), - const SizedBox(width: 4.0), - !loading - ? Text( - points.toString(), - style: TextStyle( - fontSize: 12, - fontWeight: FontWeight.bold, - color: indicator.color(context), - ), - ) - : const SizedBox( - height: 8, - width: 8, - child: CircularProgressIndicator.adaptive( - strokeWidth: 2, - ), + ), + const SizedBox(width: 4.0), + !loading + ? Text( + points.toString(), + style: TextStyle( + fontSize: 12, + fontWeight: FontWeight.bold, + color: indicator.color(context), ), - ], - ), + ) + : const SizedBox( + height: 8, + width: 8, + child: CircularProgressIndicator.adaptive( + strokeWidth: 2, + ), + ), + ], ), ), ),