Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Sort family members by display name

Neeraj Guptaab10bdac9600
diff --git a/mobile/apps/photos/lib/ui/family/family_dashboard.dart b/mobile/apps/photos/lib/ui/family/family_dashboard.dart
index 51c380cf14..953e7810c3 100644
--- a/mobile/apps/photos/lib/ui/family/family_dashboard.dart
+++ b/mobile/apps/photos/lib/ui/family/family_dashboard.dart
@@ -94,7 +94,12 @@ class FamilyDashboard extends StatelessWidget {
@override
Widget build(BuildContext context) {
- final activeMembers = members.where((member) => member.isActive).toList();
+ final visibleMembers =
+ members.where((member) => isAdmin || member.isActive).toList()
+ ..sort(_compareMembers);
+ final activeMembers = visibleMembers
+ .where((member) => member.isActive)
+ .toList();
final l10n = AppLocalizations.of(context);
return Column(
@@ -109,7 +114,7 @@ class FamilyDashboard extends StatelessWidget {
const SizedBox(height: Spacing.xl),
Text(l10n.members, style: TextStyles.h2),
const SizedBox(height: Spacing.md),
- for (final (index, member) in members.indexed) ...[
+ for (final (index, member) in visibleMembers.indexed) ...[
_FamilyMemberRow(
member: member,
isCurrentUser: _isCurrentUser(member),
@@ -121,7 +126,8 @@ class FamilyDashboard extends StatelessWidget {
avatarColor: _avatarColorFor(member),
onTap: () => onMemberTap(member),
),
- if (index < members.length - 1) const SizedBox(height: Spacing.sm),
+ if (index < visibleMembers.length - 1)
+ const SizedBox(height: Spacing.sm),
],
if (isAdmin && remainingSlots > 0) ...[
const SizedBox(height: Spacing.xl),
@@ -143,6 +149,22 @@ class FamilyDashboard extends StatelessWidget {
member.email.trim().toLowerCase() ==
userDetails.email.trim().toLowerCase();
+ int _compareMembers(FamilyMember a, FamilyMember b) {
+ if (_isCurrentUser(a)) return -1;
+ if (_isCurrentUser(b)) return 1;
+ if (isAdmin && a.isPending != b.isPending) {
+ return a.isPending ? 1 : -1;
+ }
+ if (a.isAdmin != b.isAdmin) return a.isAdmin ? -1 : 1;
+
+ final displayNameComparison = _displayNameFor(
+ a,
+ ).toLowerCase().compareTo(_displayNameFor(b).toLowerCase());
+ return displayNameComparison != 0
+ ? displayNameComparison
+ : a.email.toLowerCase().compareTo(b.email.toLowerCase());
+ }
+
String _displayNameFor(FamilyMember member) =>
_savedNameFor(member) ?? member.email;
diff --git a/mobile/apps/photos/lib/ui/family/family_plan_page.dart b/mobile/apps/photos/lib/ui/family/family_plan_page.dart
index db57c24635..ee047d2875 100644
--- a/mobile/apps/photos/lib/ui/family/family_plan_page.dart
+++ b/mobile/apps/photos/lib/ui/family/family_plan_page.dart
@@ -347,7 +347,7 @@ class _FamilyPlanPageState extends State<FamilyPlanPage> {
}
Widget _buildDashboard(BuildContext context, {required bool isAdminView}) {
- final members = _sortedMembersForDashboard(isAdminView: isAdminView);
+ final members = _userDetails.familyData?.members ?? const <FamilyMember>[];
return FamilyDashboard(
userDetails: _userDetails,
members: members,
@@ -798,28 +798,6 @@ class _FamilyPlanPageState extends State<FamilyPlanPage> {
}
}
- List<FamilyMember> _sortedMembersForDashboard({required bool isAdminView}) {
- final members = List<FamilyMember>.from(
- _userDetails.familyData?.members ?? const <FamilyMember>[],
- );
- final currentEmail = _userDetails.email.trim().toLowerCase();
-
- if (!isAdminView) {
- members.removeWhere((member) => !member.isActive);
- }
-
- members.sort((a, b) {
- if (a.email.trim().toLowerCase() == currentEmail) return -1;
- if (b.email.trim().toLowerCase() == currentEmail) return 1;
- if (isAdminView && a.isPending != b.isPending) {
- return a.isPending ? 1 : -1;
- }
- if (a.isAdmin != b.isAdmin) return a.isAdmin ? -1 : 1;
- return a.email.compareTo(b.email);
- });
- return members;
- }
-
_MonthlyPrice? _monthlyPriceForPlan(BillingPlan plan) {
if (plan.price.isEmpty) {
return null;
diff --git a/mobile/apps/photos/test/ui/family/family_dashboard_test.dart b/mobile/apps/photos/test/ui/family/family_dashboard_test.dart
index f9b0020244..a1929df918 100644
--- a/mobile/apps/photos/test/ui/family/family_dashboard_test.dart
+++ b/mobile/apps/photos/test/ui/family/family_dashboard_test.dart
@@ -191,19 +191,7 @@ void main() {
members: members,
isAdmin: true,
contactsByUserId: {
- 42: contacts.ContactRecord(
- id: 'saved-contact',
- contactUserId: 42,
- email: savedMember.email,
- data: const contacts.ContactData(
- contactUserId: 42,
- name: 'Saved member',
- ),
- profilePictureAttachmentId: null,
- isDeleted: false,
- createdAt: 1,
- updatedAt: 1,
- ),
+ 42: _contact(savedMember, name: 'Saved member'),
},
profilePictureBytesByUserId: const {},
linkedPersonIdsByUserId: const {},
@@ -310,6 +298,67 @@ void main() {
);
expect(personAvatar.personId, 'person-42');
});
+
+ testWidgets('sorts other members by their displayed name or email', (
+ tester,
+ ) async {
+ final currentUser = _member(
+ email: '[email protected]',
+ userID: 1,
+ isAdmin: true,
+ status: FamilyMemberStatus.self,
+ );
+ final zoe = _member(email: '[email protected]', userID: 2);
+ final amy = _member(email: '[email protected]', userID: 3);
+ final bob = _member(email: '[email protected]', userID: 4);
+ final members = [currentUser, zoe, amy, bob];
+
+ await tester.pumpWidget(
+ MaterialApp(
+ theme: lightThemeData,
+ localizationsDelegates: AppLocalizations.localizationsDelegates,
+ supportedLocales: AppLocalizations.supportedLocales,
+ home: Scaffold(
+ body: SingleChildScrollView(
+ child: FamilyDashboard(
+ userDetails: _userDetails(members),
+ members: members,
+ isAdmin: true,
+ contactsByUserId: {
+ 2: _contact(zoe, name: 'Zoe'),
+ 3: _contact(amy, name: 'Amy'),
+ },
+ profilePictureBytesByUserId: const {},
+ linkedPersonIdsByUserId: const {},
+ onMemberTap: (_) {},
+ onAddMember: () {},
+ remainingSlots: 0,
+ ),
+ ),
+ ),
+ ),
+ );
+
+ expect(
+ tester
+ .widgetList<MenuComponent>(find.byType(MenuComponent))
+ .map((item) => item.title),
+ ['[email protected]', 'Amy', '[email protected]', 'Zoe'],
+ );
+ });
+}
+
+contacts.ContactRecord _contact(FamilyMember member, {required String name}) {
+ return contacts.ContactRecord(
+ id: 'contact-${member.userID}',
+ contactUserId: member.userID!,
+ email: member.email,
+ data: contacts.ContactData(contactUserId: member.userID!, name: name),
+ profilePictureAttachmentId: null,
+ isDeleted: false,
+ createdAt: 1,
+ updatedAt: 1,
+ );
}
FamilyMember _member({