diff --git a/mobile/lib/ui/sharing/add_participant_page.dart b/mobile/lib/ui/sharing/add_participant_page.dart index 92c6e84e9c..f0006dac6b 100644 --- a/mobile/lib/ui/sharing/add_participant_page.dart +++ b/mobile/lib/ui/sharing/add_participant_page.dart @@ -18,18 +18,26 @@ import 'package:photos/ui/components/models/button_type.dart'; import "package:photos/ui/notification/toast.dart"; import 'package:photos/ui/sharing/user_avator_widget.dart'; import "package:photos/ui/sharing/verify_identity_dialog.dart"; +import "package:photos/utils/separators_util.dart"; + +enum ActionTypesToShow { + addViewer, + addCollaborator, +} class AddParticipantPage extends StatefulWidget { - final bool isAddingViewer; + /// Cannot be empty + final List actionTypesToShow; final List collections; - const AddParticipantPage( + AddParticipantPage( this.collections, - this.isAddingViewer, { + this.actionTypesToShow, { super.key, - }); - - bool get isToMultipleCollections => collections.length > 1; + }) : assert( + actionTypesToShow.isNotEmpty, + 'actionTypesToShow cannot be empty', + ); @override State createState() => _AddParticipantPage(); @@ -78,11 +86,7 @@ class _AddParticipantPage extends State { resizeToAvoidBottomInset: isKeypadOpen, appBar: AppBar( title: Text( - widget.isToMultipleCollections - ? S.of(context).addParticipants - : widget.isAddingViewer - ? S.of(context).addViewer - : S.of(context).addCollaborator, + _getTitle(), ), ), body: Column( @@ -132,13 +136,15 @@ class _AddParticipantPage extends State { .longPressAnEmailToVerifyEndToEndEncryption, ) : const SizedBox.shrink(), - widget.isAddingViewer - ? const SizedBox.shrink() - : MenuSectionDescriptionWidget( + widget.actionTypesToShow.contains( + ActionTypesToShow.addCollaborator, + ) + ? MenuSectionDescriptionWidget( content: S .of(context) .collaboratorsCanAddPhotosAndVideosToTheSharedAlbum, - ), + ) + : const SizedBox.shrink(), ], ), ); @@ -224,9 +230,7 @@ class _AddParticipantPage extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ const SizedBox(height: 8), - widget.isToMultipleCollections - ? _multipleActionButton() - : _singleActionButton(), + ..._actionButtons(), const SizedBox(height: 12), ], ), @@ -237,53 +241,10 @@ class _AddParticipantPage extends State { ); } - Widget _singleActionButton() { - return ButtonWidget( - buttonType: ButtonType.primary, - buttonSize: ButtonSize.large, - labelText: widget.isAddingViewer - ? S.of(context).addViewers(_selectedEmails.length) - : S.of(context).addCollaborators(_selectedEmails.length), - isDisabled: _selectedEmails.isEmpty, - onTap: () async { - final results = []; - final collections = widget.collections; - - for (String email in _selectedEmails) { - for (Collection collection in collections) { - results.add( - await collectionActions.addEmailToCollection( - context, - collection, - email, - widget.isAddingViewer - ? CollectionParticipantRole.viewer - : CollectionParticipantRole.collaborator, - ), - ); - } - } - - final noOfSuccessfullAdds = results.where((e) => e).length; - showToast( - context, - widget.isAddingViewer - ? S.of(context).viewersSuccessfullyAdded(noOfSuccessfullAdds) - : S.of(context).collaboratorsSuccessfullyAdded( - noOfSuccessfullAdds, - ), - ); - - if (!results.any((e) => e == false) && mounted) { - Navigator.of(context).pop(true); - } - }, - ); - } - - Widget _multipleActionButton() { - return Column( - children: [ + List _actionButtons() { + final widgets = []; + if (widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)) { + widgets.add( ButtonWidget( buttonType: ButtonType.primary, buttonSize: ButtonSize.large, @@ -317,9 +278,17 @@ class _AddParticipantPage extends State { } }, ), - const SizedBox(height: 8), + ); + } + if (widget.actionTypesToShow.contains( + ActionTypesToShow.addCollaborator, + )) { + widgets.add( ButtonWidget( - buttonType: ButtonType.neutral, + buttonType: + widget.actionTypesToShow.contains(ActionTypesToShow.addViewer) + ? ButtonType.neutral + : ButtonType.primary, buttonSize: ButtonSize.large, labelText: S.of(context).addCollaborators(_selectedEmails.length), isDisabled: _selectedEmails.isEmpty, @@ -351,8 +320,15 @@ class _AddParticipantPage extends State { } }, ), - ], + ); + } + final widgetsWithSpaceBetween = addSeparators( + widgets, + const SizedBox( + height: 8, + ), ); + return widgetsWithSpaceBetween; } void clearFocus() { @@ -479,4 +455,14 @@ class _AddParticipantPage extends State { return suggestedUsers; } + + String _getTitle() { + if (widget.actionTypesToShow.length > 1) { + return S.of(context).addParticipants; + } else if (widget.actionTypesToShow.first == ActionTypesToShow.addViewer) { + return S.of(context).addViewer; + } else { + return S.of(context).addCollaborator; + } + } } diff --git a/mobile/lib/ui/sharing/album_participants_page.dart b/mobile/lib/ui/sharing/album_participants_page.dart index 0f28dd5b7a..b162b1f8dd 100644 --- a/mobile/lib/ui/sharing/album_participants_page.dart +++ b/mobile/lib/ui/sharing/album_participants_page.dart @@ -54,7 +54,12 @@ class _AlbumParticipantsPageState extends State { Future _navigateToAddUser(bool addingViewer) async { await routeToPage( context, - AddParticipantPage([widget.collection], addingViewer), + AddParticipantPage( + [widget.collection], + addingViewer + ? [ActionTypesToShow.addViewer] + : [ActionTypesToShow.addCollaborator], + ), ); if (mounted) { setState(() => {}); diff --git a/mobile/lib/ui/sharing/share_collection_page.dart b/mobile/lib/ui/sharing/share_collection_page.dart index d110e156b5..0b1ab33bb9 100644 --- a/mobile/lib/ui/sharing/share_collection_page.dart +++ b/mobile/lib/ui/sharing/share_collection_page.dart @@ -92,7 +92,10 @@ class _ShareCollectionPageState extends State { // ignore: unawaited_futures routeToPage( context, - AddParticipantPage([widget.collection], true), + AddParticipantPage( + [widget.collection], + const [ActionTypesToShow.addViewer], + ), ).then( (value) => { if (mounted) {setState(() => {})}, @@ -120,7 +123,10 @@ class _ShareCollectionPageState extends State { // ignore: unawaited_futures routeToPage( context, - AddParticipantPage([widget.collection], false), + AddParticipantPage( + [widget.collection], + const [ActionTypesToShow.addCollaborator], + ), ).then( (value) => { if (mounted) {setState(() => {})}, diff --git a/mobile/lib/ui/viewer/actions/album_selection_action_widget.dart b/mobile/lib/ui/viewer/actions/album_selection_action_widget.dart index fd87150139..f75b8358ba 100644 --- a/mobile/lib/ui/viewer/actions/album_selection_action_widget.dart +++ b/mobile/lib/ui/viewer/actions/album_selection_action_widget.dart @@ -162,7 +162,7 @@ class _AlbumSelectionActionWidgetState context, AddParticipantPage( widget.selectedAlbums.albums.toList(), - false, + const [ActionTypesToShow.addViewer, ActionTypesToShow.addCollaborator], ), ); widget.selectedAlbums.clearAll();