From b4fb28380ff13c20c453c93453da5b7864a5f6f0 Mon Sep 17 00:00:00 2001 From: Christian Pauly Date: Sun, 22 Nov 2020 21:09:29 +0100 Subject: [PATCH] chore: Minor design changes in user viewer --- lib/components/user_bottom_sheet.dart | 84 +++++++++++++++++++++++---- 1 file changed, 74 insertions(+), 10 deletions(-) diff --git a/lib/components/user_bottom_sheet.dart b/lib/components/user_bottom_sheet.dart index dc8e0b63..7a9b8c69 100644 --- a/lib/components/user_bottom_sheet.dart +++ b/lib/components/user_bottom_sheet.dart @@ -36,35 +36,41 @@ class UserBottomSheet extends StatelessWidget { case 'ban': if (await _askConfirmation()) { await SimpleDialogs(context).tryRequestWithLoadingDialog(user.ban()); + Navigator.of(context).pop(); } break; case 'unban': if (await _askConfirmation()) { await SimpleDialogs(context) .tryRequestWithLoadingDialog(user.unban()); + Navigator.of(context).pop(); } break; case 'kick': if (await _askConfirmation()) { await SimpleDialogs(context).tryRequestWithLoadingDialog(user.kick()); + Navigator.of(context).pop(); } break; case 'admin': if (await _askConfirmation()) { await SimpleDialogs(context) .tryRequestWithLoadingDialog(user.setPower(100)); + Navigator.of(context).pop(); } break; case 'moderator': if (await _askConfirmation()) { await SimpleDialogs(context) .tryRequestWithLoadingDialog(user.setPower(50)); + Navigator.of(context).pop(); } break; case 'user': if (await _askConfirmation()) { await SimpleDialogs(context) .tryRequestWithLoadingDialog(user.setPower(0)); + Navigator.of(context).pop(); } break; case 'message': @@ -99,13 +105,23 @@ class UserBottomSheet extends StatelessWidget { if (onMention != null) { items.add( - PopupMenuItem(child: Text(L10n.of(context).mention), value: 'mention'), + PopupMenuItem( + child: _TextWithIcon( + L10n.of(context).mention, + Icons.alternate_email_outlined, + ), + value: 'mention'), ); } - if (user.id != Matrix.of(context).client.userID) { + if (user.id != Matrix.of(context).client.userID && + !user.room.isDirectChat) { items.add( PopupMenuItem( - child: Text(L10n.of(context).sendAMessage), value: 'message'), + child: _TextWithIcon( + L10n.of(context).sendAMessage, + Icons.send, + ), + value: 'message'), ); } if (user.canChangePowerLevel && @@ -113,7 +129,11 @@ class UserBottomSheet extends StatelessWidget { user.powerLevel != 100) { items.add( PopupMenuItem( - child: Text(L10n.of(context).makeAnAdmin), value: 'admin'), + child: _TextWithIcon( + L10n.of(context).makeAnAdmin, + Icons.arrow_upward, + ), + value: 'admin'), ); } if (user.canChangePowerLevel && @@ -121,29 +141,50 @@ class UserBottomSheet extends StatelessWidget { user.powerLevel != 50) { items.add( PopupMenuItem( - child: Text(L10n.of(context).makeAModerator), value: 'moderator'), + child: _TextWithIcon( + L10n.of(context).makeAModerator, + Icons.arrow_upward_outlined, + ), + value: 'moderator'), ); } if (user.canChangePowerLevel && user.powerLevel != 0) { items.add( PopupMenuItem( - child: Text(L10n.of(context).revokeAllPermissions), value: 'user'), + child: _TextWithIcon( + L10n.of(context).revokeAllPermissions, + Icons.arrow_downward_outlined, + ), + value: 'user'), ); } if (user.canKick) { items.add( PopupMenuItem( - child: Text(L10n.of(context).kickFromChat), value: 'kick'), + child: _TextWithIcon( + L10n.of(context).kickFromChat, + Icons.exit_to_app_outlined, + ), + value: 'kick'), ); } if (user.canBan && user.membership != Membership.ban) { items.add( - PopupMenuItem(child: Text(L10n.of(context).banFromChat), value: 'ban'), + PopupMenuItem( + child: _TextWithIcon( + L10n.of(context).banFromChat, + Icons.warning_sharp, + ), + value: 'ban'), ); - } else if (user.canBan && user.membership == Membership.ban) { + } else if (user.room.canBan && + user.powerLevel < user.room.ownPowerLevel && + user.membership == Membership.ban) { items.add( PopupMenuItem( - child: Text(L10n.of(context).removeExile), value: 'unban'), + child: _TextWithIcon( + L10n.of(context).removeExile, Icons.warning_outlined), + value: 'unban'), ); } return Center( @@ -221,3 +262,26 @@ class UserBottomSheet extends StatelessWidget { ); } } + +class _TextWithIcon extends StatelessWidget { + final String text; + final IconData iconData; + + const _TextWithIcon( + this.text, + this.iconData, { + Key key, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(iconData), + SizedBox(width: 16), + Text(text), + ], + ); + } +}