Przeglądaj źródła

Refactor addEmailToCollection

Neeraj Gupta 2 lat temu
rodzic
commit
bab9a0ea3e

+ 7 - 6
lib/ui/actions/collection/collection_sharing_actions.dart

@@ -186,11 +186,12 @@ class CollectionActions {
     }
   }
 
-  Future<bool?> addEmailToCollection(
+  // addEmailToCollection returns true if add operation was successful
+  Future<bool> addEmailToCollection(
     BuildContext context,
     Collection collection,
-    String email, {
-    CollectionParticipantRole role = CollectionParticipantRole.viewer,
+    String email,
+    CollectionParticipantRole role, {
     bool showProgress = false,
   }) async {
     if (!isValidEmail(email)) {
@@ -199,10 +200,10 @@ class CollectionActions {
         "Invalid email address",
         "Please enter a valid email address.",
       );
-      return null;
+      return false;
     } else if (email.trim() == Configuration.instance.getEmail()) {
       await showErrorDialog(context, "Oops", "You cannot share with yourself");
-      return null;
+      return false;
     }
 
     ProgressDialog? dialog;
@@ -247,7 +248,7 @@ class CollectionActions {
           ),
         ],
       );
-      return null;
+      return false;
     } else {
       try {
         final newSharees = await CollectionsService.instance

+ 2 - 2
lib/ui/sharing/add_partipant_page.dart

@@ -187,11 +187,11 @@ class _AddParticipantPage extends State<AddParticipantPage> {
                               context,
                               widget.collection,
                               emailToAdd,
-                              role: widget.isAddingViewer
+                              widget.isAddingViewer
                                   ? CollectionParticipantRole.viewer
                                   : CollectionParticipantRole.collaborator,
                             );
-                            if (result != null && result && mounted) {
+                            if (result && mounted) {
                               Navigator.of(context).pop(true);
                             }
                           },

+ 4 - 4
lib/ui/sharing/manage_album_participant.dart

@@ -78,10 +78,10 @@ class _ManageIndividualParticipantState
                         context,
                         widget.collection,
                         widget.user.email,
-                        role: CollectionParticipantRole.collaborator,
+                        CollectionParticipantRole.collaborator,
                         showProgress: true,
                       );
-                      if ((result ?? false) && mounted) {
+                      if (result && mounted) {
                         widget.user.role = CollectionParticipantRole
                             .collaborator
                             .toStringVal();
@@ -110,10 +110,10 @@ class _ManageIndividualParticipantState
                         context,
                         widget.collection,
                         widget.user.email,
-                        role: CollectionParticipantRole.viewer,
+                        CollectionParticipantRole.viewer,
                         showProgress: true,
                       );
-                      if ((result ?? false) && mounted) {
+                      if (result && mounted) {
                         widget.user.role =
                             CollectionParticipantRole.viewer.toStringVal();
                         setState(() => {});