diff --git a/commet/lib/ui/organisms/user_profile/user_profile.dart b/commet/lib/ui/organisms/user_profile/user_profile.dart index 2b4f7a069..4b8f755ac 100644 --- a/commet/lib/ui/organisms/user_profile/user_profile.dart +++ b/commet/lib/ui/organisms/user_profile/user_profile.dart @@ -511,15 +511,17 @@ class _UserProfileState extends State { } Future clearBio() async { - setState(() { - bioText = null; - }); + if (await AdaptiveDialog.confirmation(context) == true) { + setState(() { + bioText = null; + }); - await widget.client.getComponent()?.removeBio(); + await widget.client.getComponent()?.removeBio(); - component.getProfile(widget.userId).then((value) async { - await stateFromProfile(value); - }); + component.getProfile(widget.userId).then((value) async { + await stateFromProfile(value); + }); + } } String get labelProfileYourBadges => Intl.message("Your Badges", diff --git a/commet/lib/ui/organisms/user_profile/user_profile_view.dart b/commet/lib/ui/organisms/user_profile/user_profile_view.dart index 91d5fa5b1..c2c5f4d02 100644 --- a/commet/lib/ui/organisms/user_profile/user_profile_view.dart +++ b/commet/lib/ui/organisms/user_profile/user_profile_view.dart @@ -339,7 +339,9 @@ class UserProfileViewState extends State { CrossAxisAlignment .end, children: [ - if (localTime != null) + if (localTime != null && + widget.timezone != + null) userLocalTime(), badges(), ], @@ -493,54 +495,49 @@ class UserProfileViewState extends State { List contextMenuItems(BuildContext context) { return [ if (widget.isSelf) - tiamat.ContextMenuItem( + profileMenuItem( text: promptProfileChangeBanner, onPressed: () => widget.onSetBanner?.call(), icon: Icons.image), if (widget.isSelf) - tiamat.ContextMenuItem( + profileMenuItem( text: promptProfileSetStatus, onPressed: () => widget.onSetStatus?.call(), + onClearPressed: widget.presence?.message != null + ? () => widget.clearStatus?.call() + : null, icon: Icons.short_text), - if (widget.isSelf && widget.presence?.message != null) - tiamat.ContextMenuItem( - text: promptProfileClearStatus, - onPressed: () => widget.clearStatus?.call(), - icon: Icons.delete), if (widget.isSelf) - tiamat.ContextMenuItem( + profileMenuItem( text: promptProfileSetBadges, onPressed: () => widget.editBadges?.call(), icon: Icons.star), if (widget.isSelf) - tiamat.ContextMenuItem( + profileMenuItem( text: promptProfileSetBio, onPressed: () => widget.setBio?.call(), - icon: Icons.text_snippet), - if (widget.isSelf && widget.bio != null) - tiamat.ContextMenuItem( - text: promptProfileClearBio, - onPressed: () => widget.clearBio?.call(), - icon: Icons.delete), + icon: Icons.text_snippet, + onClearPressed: () => widget.clearBio?.call()), if (widget.isSelf) - tiamat.ContextMenuItem( + profileMenuItem( text: promptProfileShareTimezone, onPressed: () => widget.shareCurrentTimezone?.call(), - icon: Icons.share_arrival_time), - if (widget.isSelf && widget.timezone != null) - tiamat.ContextMenuItem( - text: promptProfileClearTimezone, - onPressed: () => widget.removeTimezone?.call(), - icon: Icons.timer_off), + icon: Icons.share_arrival_time, + onClearPressed: widget.timezone != null + ? () => widget.removeTimezone?.call() + : null), if (widget.isSelf) - tiamat.ContextMenuItem( + profileMenuItem( text: promptProfileEditColorScheme, onPressed: () => setState(() { editingColorScheme = true; }), icon: Icons.color_lens), - tiamat.ContextMenuItem( + profileMenuItem( text: promptProfileSetColorOverride, + onClearPressed: widget.hasColorOverride + ? () => widget.setColorOverride?.call(null) + : null, onPressed: () async { var color = await AdaptiveDialog.show( title: promptProfileSetColorOverride, @@ -587,9 +584,11 @@ class UserProfileViewState extends State { } }, icon: Icons.colorize), - tiamat.ContextMenuItem( + profileMenuItem( text: "Set Nickame", icon: Icons.badge, + onClearPressed: + widget.hasPetName ? () => widget.setPetName?.call(null) : null, onPressed: () async { final text = await AdaptiveDialog.textPrompt( context, @@ -602,27 +601,77 @@ class UserProfileViewState extends State { } }, ), - if (widget.hasPetName) - tiamat.ContextMenuItem( - text: "Clear Nickname", - icon: Icons.remove, - onPressed: () => widget.setPetName?.call(null), - ), - if (widget.hasColorOverride) - tiamat.ContextMenuItem( - text: promptProfileClearColorOverride, - icon: Icons.remove, - onPressed: () async { - widget.setColorOverride?.call(null); - }), if (preferences.developerMode.value) - tiamat.ContextMenuItem( + profileMenuItem( text: promptProfileShowRawProfile, onPressed: () => widget.showSource?.call(), icon: Icons.code), ]; } + tiamat.ContextMenuItem profileMenuItem( + {required String text, + required IconData icon, + required Function onPressed, + Function? onClearPressed}) { + return tiamat.ContextMenuItem( + text: text, + icon: icon, + onPressed: onPressed, + customBuilder: (context, onClicked, {closeMenu}) { + var c = Theme.of(context).colorScheme.onSurface; + + return Material( + color: Colors.transparent, + child: Padding( + padding: const EdgeInsets.all(4.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisSize: MainAxisSize.max, + spacing: 8, + children: [ + Expanded( + child: InkWell( + onTap: onClicked, + borderRadius: BorderRadius.circular(8), + child: Container( + padding: const EdgeInsets.fromLTRB(4, 8, 4, 8), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.max, + spacing: 8, + children: [ + Icon( + icon, + color: c, + size: 20, + ), + tiamat.Text(text, + type: tiamat.TextType.body, + maxLines: 1, + color: c), + ], + ))), + ), + if (onClearPressed != null) + tiamat.IconButton( + icon: Icons.close, + size: 18, + iconColor: Colors.red, + onPressed: () { + onClearPressed.call(); + closeMenu?.call(); + }, + ), + ], + ), + ), + ); + }, + ); + } + Widget buildColorSchemeEditor() { var run = 8; var count = run * 2; diff --git a/tiamat/lib/atoms/context_menu.dart b/tiamat/lib/atoms/context_menu.dart index 264848b45..e9568f26b 100644 --- a/tiamat/lib/atoms/context_menu.dart +++ b/tiamat/lib/atoms/context_menu.dart @@ -315,7 +315,7 @@ class ContextMenuItem { return Material( color: Colors.transparent, child: Padding( - padding: const EdgeInsets.all(3.0), + padding: const EdgeInsets.all(4.0), child: InkWell( onTap: onClicked, borderRadius: BorderRadius.circular(8),