From 85a3d65d2353777c3cd55a204c221dfa33bde6c9 Mon Sep 17 00:00:00 2001 From: Garrett Watson Date: Thu, 15 Feb 2024 15:10:25 -0500 Subject: [PATCH] feat: rework personal_profile model + start testing new layouts for My Profile dialog --- lib/models/personal_profile.dart | 32 +++++++++++++++++++++ lib/models/users/user_profile.dart | 29 ++++++++++++++++--- lib/widgets/my_profile_dialog.dart | 45 +++++++++++++++++++----------- 3 files changed, 85 insertions(+), 21 deletions(-) diff --git a/lib/models/personal_profile.dart b/lib/models/personal_profile.dart index 7443875..8d2f5d2 100644 --- a/lib/models/personal_profile.dart +++ b/lib/models/personal_profile.dart @@ -1,3 +1,4 @@ +import 'package:flutter/material.dart'; import 'package:recon/auxiliary.dart'; import 'package:recon/models/users/entitlement.dart'; import 'package:recon/models/users/user_profile.dart'; @@ -9,6 +10,7 @@ class PersonalProfile { final DateTime? publicBanExpiration; final String? publicBanType; final bool twoFactor; + final List tags; final UserProfile userProfile; final List entitlements; final List supporterMetadata; @@ -20,6 +22,7 @@ class PersonalProfile { required this.publicBanExpiration, required this.publicBanType, required this.twoFactor, + required this.tags, required this.userProfile, required this.entitlements, required this.supporterMetadata, @@ -33,6 +36,7 @@ class PersonalProfile { publicBanExpiration: DateTime.tryParse(map["publicBanExpiration"] ?? ""), publicBanType: map["publicBanType"], twoFactor: map["2fa_login"] ?? false, + tags: (map["tags"] ?? []).cast(), userProfile: UserProfile.fromMap(map["profile"]), entitlements: ((map["entitlements"] ?? []) as List).map((e) => Entitlement.fromMap(e)).toList(), supporterMetadata: ((map["supporterMetadata"] ?? []) as List).map((e) => SupporterMetadata.fromMap(e)).toList(), @@ -41,6 +45,34 @@ class PersonalProfile { bool get isPatreonSupporter => supporterMetadata.whereType().any((element) => element.isActiveSupporter); + + static final List accountTypes = [ + AccountType(label: "Standard Account", color: const Color(0xFF86888B)), + AccountType(label: "Patreon Supporter", color: const Color(0xFFFF7676)), + AccountType(label: "Resonite Mentor", color: const Color(0xFF59EB5C)), + AccountType(label: "Resonite Moderator", color: const Color(0xFF61D1FA)), + AccountType(label: "Resonite Team", color: const Color.fromARGB(255, 255, 230, 0)), + ]; + + AccountType get accountType => tags.contains("team member") + ? accountTypes[4] + : tags.contains("moderator") + ? accountTypes[3] + : tags.contains("mentor") + ? accountTypes[2] + : isPatreonSupporter + ? accountTypes[1] + : accountTypes[0]; +} + +class AccountType { + final String label; + final Color color; + + AccountType({ + required this.label, + required this.color, + }); } class StorageQuota { diff --git a/lib/models/users/user_profile.dart b/lib/models/users/user_profile.dart index f78504a..edfee61 100644 --- a/lib/models/users/user_profile.dart +++ b/lib/models/users/user_profile.dart @@ -1,17 +1,38 @@ class UserProfile { final String iconUrl; + final String tagline; + final String description; + final List displayBadges; - UserProfile({required this.iconUrl}); + UserProfile({ + required this.iconUrl, + required this.tagline, + required this.description, + required this.displayBadges, + }); - factory UserProfile.empty() => UserProfile(iconUrl: ""); + factory UserProfile.empty() => UserProfile( + iconUrl: "", + tagline: "", + description: "", + displayBadges: [], + ); factory UserProfile.fromMap(Map? map) { - return UserProfile(iconUrl: map?["iconUrl"] ?? ""); + return UserProfile( + iconUrl: map?["iconUrl"] ?? "", + tagline: map?["tagline"] ?? "", + description: map?["description"] ?? "", + displayBadges: map?["displayBadges"]?.cast() ?? [], + ); } Map toMap() { return { "iconUrl": iconUrl, + "tagline": tagline, + "description": description, + "displayBadges": displayBadges, }; } -} \ No newline at end of file +} diff --git a/lib/widgets/my_profile_dialog.dart b/lib/widgets/my_profile_dialog.dart index 7e5b49b..05b411b 100644 --- a/lib/widgets/my_profile_dialog.dart +++ b/lib/widgets/my_profile_dialog.dart @@ -48,24 +48,25 @@ class _MyProfileDialogState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, - crossAxisAlignment: CrossAxisAlignment.end, + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.center, children: [ - Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(profile.username, style: tt.titleLarge), - Text( - profile.email, - style: - tt.labelMedium?.copyWith(color: Theme.of(context).colorScheme.onSurface.withAlpha(150)), - ) - ], - ), GenericAvatar( imageUri: Aux.resdbToHttp(profile.userProfile.iconUrl), - radius: 24, - ) + radius: 32, + ), + Padding( + padding: const EdgeInsets.only(left: 12), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(profile.username, style: tt.titleLarge), + Text( + profile.accountType.label, + style: tt.labelMedium?.copyWith(color: profile.accountType.color), + ), + ], + )), ], ), const SizedBox( @@ -85,10 +86,10 @@ class _MyProfileDialogState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - "2FA: ", + "Email: ", style: tt.labelLarge, ), - Text(profile.twoFactor ? "Enabled" : "Disabled") + Text(profile.email) ], ), Row( @@ -101,6 +102,16 @@ class _MyProfileDialogState extends State { Text(profile.isPatreonSupporter ? "Yes" : "No") ], ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "2FA: ", + style: tt.labelLarge, + ), + Text(profile.twoFactor ? "Enabled" : "Disabled") + ], + ), if (profile.publicBanExpiration?.isAfter(DateTime.now()) ?? false) Row( mainAxisAlignment: MainAxisAlignment.spaceBetween,