diff --git a/lib/forez/ui/screens/forez_directory_screen.dart b/lib/forez/ui/screens/forez_directory_screen.dart index 4c9a0da..f3969bb 100644 --- a/lib/forez/ui/screens/forez_directory_screen.dart +++ b/lib/forez/ui/screens/forez_directory_screen.dart @@ -19,7 +19,12 @@ import 'package:flutter/material.dart'; /// /// @author Pierre Hubert -enum _PopupMenuActions { PRIVATE_CONVERSATION, CANCEL_INVITATION } +enum _PopupMenuActions { + PRIVATE_CONVERSATION, + CANCEL_INVITATION, + ACCEPT_REQUEST, + REJECT_REQUEST +} class ForezDirectoryScreen extends StatefulWidget { @override @@ -65,6 +70,16 @@ class _ForezDirectoryScreenState extends State { await GroupsHelper.cancelInvitation(forezGroup.id, user.id); _key.currentState.refresh(); break; + + case _PopupMenuActions.ACCEPT_REQUEST: + await GroupsHelper.respondRequest(forezGroup.id, user.id, true); + _key.currentState.refresh(); + break; + + case _PopupMenuActions.REJECT_REQUEST: + await GroupsHelper.respondRequest(forezGroup.id, user.id, false); + _key.currentState.refresh(); + break; } } catch (e, s) { logError(e, s); @@ -90,12 +105,40 @@ class _ForezMemberTile extends StatelessWidget { leading: AccountImageWidget(user: user), title: Text(user.fullName), subtitle: Text(member.membershipText), - trailing: user.id == userID() - ? null - : PopupMenuButton( - itemBuilder: (c) => popupMenuItems, - onSelected: (a) => selectedAction(a, user), - ), + trailing: member.level == GroupMembershipLevel.PENDING + ? _buildRequestedButton() + : _buildPopupMenuButton(), + ); + + Widget _buildPopupMenuButton() => user.id == userID() + ? null + : PopupMenuButton( + itemBuilder: (c) => popupMenuItems, + onSelected: (a) => selectedAction(a, user), + ); + + Widget _buildRequestedButton() => IntrinsicWidth( + child: Row( + children: [ + ElevatedButton( + onPressed: () => + selectedAction(_PopupMenuActions.ACCEPT_REQUEST, user), + child: Icon(Icons.check), + style: ButtonStyle( + visualDensity: VisualDensity.compact, + backgroundColor: MaterialStateProperty.all(Colors.green)), + ), + SizedBox(width: 5), + OutlinedButton( + onPressed: () => + selectedAction(_PopupMenuActions.REJECT_REQUEST, user), + child: Icon(Icons.close), + style: ButtonStyle( + visualDensity: VisualDensity.compact, + foregroundColor: MaterialStateProperty.all(Colors.redAccent)), + ), + ], + ), ); List> get popupMenuItems => [