π End-to-end encrypted cloud for everything.
Dart 2faandroidauthye2eeencryptionend-to-end-encryptionfluttergolanggoogle-photosgoogle-photos-alternativeiosopensourcephotosprivacyprivacy-toolstypescriptzero-knowledge
Refactor add participants page
ashilkn9605637e50a3
diff --git a/mobile/lib/ui/sharing/add_participant_page.dart b/mobile/lib/ui/sharing/add_participant_page.dartindex 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> actionTypesToShow;final List<Collection> 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',+ );@overrideState<StatefulWidget> createState() => _AddParticipantPage();@@ -78,11 +86,7 @@ class _AddParticipantPage extends State<AddParticipantPage> {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<AddParticipantPage> {.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<AddParticipantPage> {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<AddParticipantPage> {);}- 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 = <bool>[];- 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<Widget> _actionButtons() {+ final widgets = <Widget>[];+ if (widget.actionTypesToShow.contains(ActionTypesToShow.addViewer)) {+ widgets.add(ButtonWidget(buttonType: ButtonType.primary,buttonSize: ButtonSize.large,@@ -317,9 +278,17 @@ class _AddParticipantPage extends State<AddParticipantPage> {}},),- 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<AddParticipantPage> {}},),- ],+ );+ }+ final widgetsWithSpaceBetween = addSeparators(+ widgets,+ const SizedBox(+ height: 8,+ ),);+ return widgetsWithSpaceBetween;}void clearFocus() {@@ -479,4 +455,14 @@ class _AddParticipantPage extends State<AddParticipantPage> {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.dartindex e51f436844..cd61e44f5b 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<AlbumParticipantsPage> {Future<void> _navigateToAddUser(bool addingViewer) async {await routeToPage(context,- AddParticipantPage(widget.collection as List<Collection>, addingViewer),+ AddParticipantPage(+ widget.collection as List<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.dartindex 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<ShareCollectionPage> {// ignore: unawaited_futuresrouteToPage(context,- AddParticipantPage([widget.collection], true),+ AddParticipantPage(+ [widget.collection],+ const [ActionTypesToShow.addViewer],+ ),).then((value) => {if (mounted) {setState(() => {})},@@ -120,7 +123,10 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {// ignore: unawaited_futuresrouteToPage(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.dartindex 9ac2dc6737..f544d7879c 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 _AlbumSelectionActionWidgetStatecontext,AddParticipantPage(widget.selectedAlbums.albums.toList(),- false,+ const [ActionTypesToShow.addViewer, ActionTypesToShow.addCollaborator],),);widget.selectedAlbums.clearAll();