refactor: analytics overview redesign (#2881)

This commit is contained in:
ggurdin 2025-05-22 16:38:53 -04:00 committed by GitHub
parent 31c909489f
commit e3246f1603
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 231 additions and 399 deletions

View file

@ -1,7 +1,6 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:badges/badges.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:matrix/matrix.dart';
@ -16,7 +15,6 @@ import 'package:fluffychat/pangea/public_spaces/public_room_bottom_sheet.dart';
import 'package:fluffychat/utils/stream_extension.dart';
import 'package:fluffychat/widgets/adaptive_dialogs/user_dialog.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/unread_rooms_badge.dart';
import '../../config/themes.dart';
import '../../widgets/matrix.dart';
@ -179,62 +177,35 @@ class ChatListViewBody extends StatelessWidget {
// ),
// shrinkWrap: true,
// scrollDirection: Axis.horizontal,
if (!controller.isSearchMode)
SingleChildScrollView(
padding: const EdgeInsets.symmetric(
horizontal: 12.0,
vertical: 16.0,
),
scrollDirection: Axis.horizontal,
child: Row(
// Pangea#
children: [
if (AppConfig.separateChatTypes)
ActiveFilter.messages
else
ActiveFilter.allChats,
// #Pangea
if (AppConfig.separateChatTypes)
ActiveFilter.groups,
// Pangea#
ActiveFilter.unread,
// #Pangea
// if (spaceDelegateCandidates.isNotEmpty &&
// !controller.widget.displayNavigationRail)
if (!AppConfig.displayNavigationRail &&
!FluffyThemes.isColumnMode(context))
// Pangea#
ActiveFilter.spaces,
]
.map(
// #Pangea
// (filter) => Padding(
(filter) => UnreadRoomsBadge(
filter: (_) => filter == ActiveFilter.unread,
badgePosition: BadgePosition.topEnd(
top: -12,
end: -6,
),
child: Padding(
// Pangea#
padding: const EdgeInsets.symmetric(
horizontal: 4.0,
),
child: FilterChip(
selected:
filter == controller.activeFilter,
onSelected: (_) =>
controller.setActiveFilter(filter),
label: Text(
filter.toLocalizedString(context),
),
),
),
),
)
.toList(),
),
),
// children: [
// if (AppConfig.separateChatTypes)
// ActiveFilter.messages
// else
// ActiveFilter.allChats,
// ActiveFilter.unread,
// if (spaceDelegateCandidates.isNotEmpty &&
// !controller.widget.displayNavigationRail)
// ActiveFilter.spaces,
// ]
// .map(
// (filter) => Padding(
// padding: const EdgeInsets.symmetric(
// horizontal: 4.0,
// ),
// child: FilterChip(
// selected: filter == controller.activeFilter,
// onSelected: (_) =>
// controller.setActiveFilter(filter),
// label: Text(
// filter.toLocalizedString(context),
// ),
// ),
// ),
// )
// .toList(),
// ),
// ),
// Pangea#
if (controller.isSearchMode)
SearchTitle(
title: L10n.of(context).chats,

View file

@ -15,6 +15,9 @@ class NaviRailItem extends StatelessWidget {
final Widget icon;
final Widget? selectedIcon;
final bool Function(Room)? unreadBadgeFilter;
// #Pangea
final Color? backgroundColor;
// Pangea#
const NaviRailItem({
required this.toolTip,
@ -23,6 +26,9 @@ class NaviRailItem extends StatelessWidget {
required this.icon,
this.selectedIcon,
this.unreadBadgeFilter,
// #Pangea
this.backgroundColor,
// Pangea#
super.key,
});
@override
@ -70,9 +76,15 @@ class NaviRailItem extends StatelessWidget {
curve: FluffyThemes.animationCurve,
child: Material(
borderRadius: borderRadius,
color: isSelected
? theme.colorScheme.primaryContainer
: theme.colorScheme.surfaceContainerHigh,
// #Pangea
// color: isSelected
// ? theme.colorScheme.primaryContainer
// : theme.colorScheme.surfaceContainerHigh,
color: backgroundColor ??
(isSelected
? theme.colorScheme.primaryContainer
: theme.colorScheme.surfaceContainerHigh),
// Pangea#
child: Tooltip(
message: toolTip,
child: InkWell(

View file

@ -0,0 +1,41 @@
import 'package:flutter/material.dart';
import 'package:fluffychat/widgets/hover_builder.dart';
class LearningProgressIndicatorButton extends StatelessWidget {
final VoidCallback? onPressed;
final Widget child;
const LearningProgressIndicatorButton({
super.key,
required this.onPressed,
required this.child,
});
@override
Widget build(BuildContext context) {
return MouseRegion(
cursor: SystemMouseCursors.click,
child: HoverBuilder(
builder: (context, hovered) {
return GestureDetector(
onTap: onPressed,
child: Container(
decoration: BoxDecoration(
color: hovered
? Theme.of(context).colorScheme.primary.withAlpha(50)
: Colors.transparent,
borderRadius: BorderRadius.circular(36.0),
),
padding: const EdgeInsets.symmetric(
vertical: 2.0,
horizontal: 4.0,
),
child: child,
),
);
},
),
);
}
}

View file

@ -2,22 +2,16 @@ import 'dart:async';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:go_router/go_router.dart';
import 'package:matrix/matrix.dart';
import 'package:fluffychat/pangea/analytics_details_popup/analytics_details_popup.dart';
import 'package:fluffychat/pangea/analytics_misc/construct_list_model.dart';
import 'package:fluffychat/pangea/analytics_misc/construct_type_enum.dart';
import 'package:fluffychat/pangea/analytics_misc/get_analytics_controller.dart';
import 'package:fluffychat/pangea/analytics_summary/learning_progress_bar.dart';
import 'package:fluffychat/pangea/analytics_summary/learning_settings_button.dart';
import 'package:fluffychat/pangea/analytics_summary/level_badge.dart';
import 'package:fluffychat/pangea/analytics_summary/learning_progress_indicator_button.dart';
import 'package:fluffychat/pangea/analytics_summary/level_bar_popup.dart';
import 'package:fluffychat/pangea/analytics_summary/progress_indicator.dart';
import 'package:fluffychat/pangea/analytics_summary/progress_indicators_enum.dart';
import 'package:fluffychat/pangea/learning_settings/pages/settings_learning.dart';
import 'package:fluffychat/widgets/avatar.dart';
import 'package:fluffychat/widgets/matrix.dart';
/// A summary of "My Analytics" shown at the top of the chat list
@ -40,7 +34,6 @@ class LearningProgressIndicatorsState
StreamSubscription<AnalyticsStreamUpdate>? _analyticsSubscription;
StreamSubscription? _languageSubscription;
Profile? _profile;
@override
void initState() {
@ -60,12 +53,6 @@ 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
@ -100,161 +87,122 @@ class LearningProgressIndicatorsState
return const SizedBox();
}
final userL1 = MatrixState.pangeaController.languageController.userL1;
final userL2 = MatrixState.pangeaController.languageController.userL2;
final mxid = client.userID ?? L10n.of(context).user;
final displayname = _profile?.displayName ?? mxid.localpart ?? mxid;
return LayoutBuilder(
builder: (context, constraints) {
return Row(
children: [
Tooltip(
message: L10n.of(context).settings,
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () => context.go("/rooms/settings"),
child: Padding(
padding: const EdgeInsets.only(
bottom: 8.0,
right: 8.0,
),
child: Stack(
clipBehavior: Clip.none, // Allow overflow
children: [
FutureBuilder<Profile>(
future: client.fetchOwnProfile(),
builder: (context, snapshot) => Stack(
alignment: Alignment.center,
children: [
Material(
color: Colors.transparent,
borderRadius: BorderRadius.circular(99),
child: Avatar(
mxContent: snapshot.data?.avatarUrl,
name: snapshot.data?.displayName ??
client.userID!.localpart,
size: 60,
),
return Row(
children: [
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Row(
spacing: 16.0,
children: ConstructTypeEnum.values
.map(
(c) => LearningProgressIndicatorButton(
onPressed: () {
showDialog<AnalyticsPopupWrapper>(
context: context,
builder: (context) => AnalyticsPopupWrapper(
view: c,
),
);
},
child: ProgressIndicatorBadge(
indicator: c.indicator,
loading: _loading,
points: uniqueLemmas(c.indicator),
),
],
),
)
.toList(),
),
),
LearningProgressIndicatorButton(
onPressed: () => showDialog(
context: context,
builder: (c) => const SettingsLearning(),
barrierDismissible: false,
),
child: Row(
children: [
if (userL1 != null && userL2 != null)
Text(
userL1.langCodeShort.toUpperCase(),
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
if (userL1 != null && userL2 != null)
const Icon(Icons.chevron_right_outlined),
if (userL2 != null)
Text(
userL2.langCodeShort.toUpperCase(),
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
],
),
),
],
),
const SizedBox(height: 6),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4.0),
child: MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
showDialog<LevelBarPopup>(
context: context,
builder: (c) => const LevelBarPopup(),
);
},
child: Row(
spacing: 8.0,
children: [
Expanded(
child: LearningProgressBar(
level: _constructsModel.level,
totalXP: _constructsModel.totalXP,
height: 24.0,
),
),
Positioned(
bottom: -3,
right: -3,
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.settings_outlined,
color: Theme.of(context).colorScheme.primary,
weight: 1000,
),
),
Text(
"${_constructsModel.level}",
style: Theme.of(context)
.textTheme
.titleLarge
?.copyWith(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
],
),
),
),
),
),
const SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
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,
builder: (c) => const SettingsLearning(),
barrierDismissible: false,
),
l2: userL2?.langCode.toUpperCase(),
),
],
),
const SizedBox(height: 6),
Row(
spacing: 6.0,
children: ConstructTypeEnum.values
.map(
(c) => ProgressIndicatorBadge(
points: uniqueLemmas(c.indicator),
loading: _loading,
onTap: () {
showDialog<AnalyticsPopupWrapper>(
context: context,
builder: (context) => AnalyticsPopupWrapper(
view: c,
),
);
},
indicator: c.indicator,
mini: constraints.maxWidth < 300,
),
)
.toList(),
),
const SizedBox(height: 6),
MouseRegion(
cursor: SystemMouseCursors.click,
child: GestureDetector(
onTap: () {
showDialog<LevelBarPopup>(
context: context,
builder: (c) => const LevelBarPopup(),
);
},
child: SizedBox(
height: 26,
child: Stack(
alignment: Alignment.center,
children: [
Positioned(
left: 16,
right: 0,
child: LearningProgressBar(
level: _constructsModel.level,
totalXP: _constructsModel.totalXP,
),
),
Positioned(
left: 0,
child: LevelBadge(
level: _constructsModel.level,
mini: constraints.maxWidth < 300,
),
),
],
),
),
),
),
],
),
),
],
);
},
const SizedBox(height: 16.0),
],
),
),
],
);
}
}

View file

@ -1,57 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/pangea/common/widgets/pressable_button.dart';
/// A badge that represents one learning progress indicator (i.e., construct uses)
class LearningSettingsButton extends StatelessWidget {
final String? l2;
final VoidCallback onTap;
const LearningSettingsButton({
super.key,
this.l2,
required this.onTap,
});
@override
Widget build(BuildContext context) {
return Row(
mainAxisSize: MainAxisSize.min,
spacing: 4.0,
children: [
Text(
l2 ?? "?",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
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_outlined,
color: Theme.of(context).colorScheme.primary,
weight: 1000,
),
),
),
),
],
);
}
}

View file

@ -1,47 +0,0 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/l10n.dart';
import 'package:fluffychat/pangea/analytics_summary/level_bar_popup.dart';
import 'package:fluffychat/pangea/common/widgets/pressable_button.dart';
class LevelBadge extends StatelessWidget {
final int level;
final bool mini;
const LevelBadge({
required this.level,
this.mini = false,
super.key,
});
@override
Widget build(BuildContext context) {
return PressableButton(
color: Theme.of(context).colorScheme.surfaceBright,
borderRadius: BorderRadius.circular(15),
buttonHeight: 2.5,
onPressed: () {
showDialog<LevelBarPopup>(
context: context,
builder: (c) => const LevelBarPopup(),
);
},
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(15),
color: Theme.of(context).colorScheme.surfaceBright,
),
padding: const EdgeInsets.symmetric(horizontal: 4, vertical: 2),
child: Text(
"${mini ? "$level" : L10n.of(context).levelShort(level)}",
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.primary,
),
),
),
);
}
}

View file

@ -10,7 +10,6 @@ class AnimatedLevelBar extends StatefulWidget {
final double beginWidth;
final double endWidth;
final Color primaryColor;
final Color highlightColor;
const AnimatedLevelBar({
super.key,
@ -18,7 +17,6 @@ class AnimatedLevelBar extends StatefulWidget {
required this.beginWidth,
required this.endWidth,
required this.primaryColor,
required this.highlightColor,
});
@override
@ -97,20 +95,6 @@ class AnimatedLevelBarState extends State<AnimatedLevelBar>
),
),
),
Positioned(
top: 2,
left: 8,
child: Container(
height: 6,
width: _animation.value >= 16 ? _animation.value - 16 : 0,
decoration: BoxDecoration(
color: widget.highlightColor,
borderRadius: const BorderRadius.all(
Radius.circular(AppConfig.borderRadius),
),
),
),
),
],
);
},

View file

@ -37,8 +37,7 @@ class LevelBarState extends State<LevelBar> {
height: widget.progressBarDetails.height,
beginWidth: prevWidth,
endWidth: width,
primaryColor: AppConfig.gold,
highlightColor: AppConfig.goldLight,
primaryColor: AppConfig.goldLight,
);
}
}

View file

@ -1,80 +1,51 @@
import 'package:flutter/material.dart';
import 'package:fluffychat/pangea/analytics_summary/progress_indicators_enum.dart';
import 'package:fluffychat/pangea/common/widgets/pressable_button.dart';
/// A badge that represents one learning progress indicator (i.e., construct uses)
class ProgressIndicatorBadge extends StatelessWidget {
final bool loading;
final int points;
final VoidCallback onTap;
final ProgressIndicatorEnum indicator;
final bool mini;
const ProgressIndicatorBadge({
super.key,
required this.onTap,
required this.indicator,
required this.loading,
required this.points,
this.mini = false,
});
@override
Widget build(BuildContext context) {
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,
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Icon(
size: 18,
indicator.icon,
color: indicator.color(context),
weight: 1000,
),
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,
),
if (!mini) ...[
const SizedBox(width: 4.0),
Text(
indicator.tooltip(context),
const SizedBox(width: 6.0),
!loading
? Text(
points.toString(),
style: TextStyle(
fontSize: 12,
fontSize: 14,
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,
),
),
],
),
),
],
),
);
}

View file

@ -90,16 +90,26 @@ class SpacesNavigationRail extends StatelessWidget {
onTap: () => isColumnMode
? onGoToChats()
: context.go("/rooms/homepage"),
icon: const Padding(
padding: EdgeInsets.all(10.0),
child: Icon(Icons.home_outlined),
),
selectedIcon: const Padding(
padding: EdgeInsets.all(10.0),
child: Icon(Icons.home),
backgroundColor: Colors.transparent,
icon: FutureBuilder<Profile>(
future: client.fetchOwnProfile(),
builder: (context, snapshot) => Stack(
alignment: Alignment.center,
children: [
Material(
color: Colors.transparent,
borderRadius: BorderRadius.circular(99),
child: Avatar(
mxContent: snapshot.data?.avatarUrl,
name: snapshot.data?.displayName ??
client.userID!.localpart,
size: 45,
),
),
],
),
),
toolTip: L10n.of(context).home,
unreadBadgeFilter: (room) => true,
);
}
i--;