Selaa lähdekoodia

Refactor: Separate method to enable or disable url

Neeraj Gupta 2 vuotta sitten
vanhempi
commit
009c23c62a

+ 38 - 39
lib/ui/actions/collection/collection_sharing_actions.dart

@@ -29,48 +29,10 @@ class CollectionActions {
 
   CollectionActions(this.collectionsService);
 
-  Future<bool> publicLinkToggle(
+  Future<bool> enableUrl(
     BuildContext context,
     Collection collection,
-    bool enable,
   ) async {
-    // confirm if user wants to disable the url
-    if (!enable) {
-      final ButtonAction? result = await showActionSheet(
-        context: context,
-        buttons: [
-          ButtonWidget(
-            buttonType: ButtonType.critical,
-            isInAlert: true,
-            shouldStickToDarkTheme: true,
-            buttonAction: ButtonAction.first,
-            shouldSurfaceExecutionStates: true,
-            labelText: "Yes, remove",
-            onTap: () async {
-              await CollectionsService.instance.disableShareUrl(collection);
-            },
-          ),
-          const ButtonWidget(
-            buttonType: ButtonType.secondary,
-            buttonAction: ButtonAction.cancel,
-            isInAlert: true,
-            shouldStickToDarkTheme: true,
-            labelText: "Cancel",
-          )
-        ],
-        title: "Remove public link",
-        body:
-            'This will remove the public link for accessing "${collection.name}".',
-      );
-      if (result != null) {
-        if (result == ButtonAction.error) {
-          showGenericErrorDialog(context: context);
-        }
-        return result == ButtonAction.first;
-      } else {
-        return false;
-      }
-    }
     final dialog = createProgressDialog(
       context,
       "Creating link...",
@@ -92,6 +54,43 @@ class CollectionActions {
     }
   }
 
+  Future<bool> disableUrl(BuildContext context, Collection collection) async {
+    final ButtonAction? result = await showActionSheet(
+      context: context,
+      buttons: [
+        ButtonWidget(
+          buttonType: ButtonType.critical,
+          isInAlert: true,
+          shouldStickToDarkTheme: true,
+          buttonAction: ButtonAction.first,
+          shouldSurfaceExecutionStates: true,
+          labelText: "Yes, remove",
+          onTap: () async {
+            await CollectionsService.instance.disableShareUrl(collection);
+          },
+        ),
+        const ButtonWidget(
+          buttonType: ButtonType.secondary,
+          buttonAction: ButtonAction.cancel,
+          isInAlert: true,
+          shouldStickToDarkTheme: true,
+          labelText: "Cancel",
+        )
+      ],
+      title: "Remove public link",
+      body:
+          'This will remove the public link for accessing "${collection.name}".',
+    );
+    if (result != null) {
+      if (result == ButtonAction.error) {
+        showGenericErrorDialog(context: context);
+      }
+      return result == ButtonAction.first;
+    } else {
+      return false;
+    }
+  }
+
   Future<Collection?> createSharedCollectionLink(
     BuildContext context,
     List<File> files,

+ 1 - 2
lib/ui/sharing/manage_links_widget.dart

@@ -226,10 +226,9 @@ class _ManageSharedLinkWidgetState extends State<ManageSharedLinkWidget> {
                     menuItemColor: getEnteColorScheme(context).fillFaint,
                     pressedColor: getEnteColorScheme(context).fillFaint,
                     onTap: () async {
-                      final bool result = await sharingActions.publicLinkToggle(
+                      final bool result = await sharingActions.disableUrl(
                         context,
                         widget.collection!,
-                        false,
                       );
                       if (result && mounted) {
                         Navigator.of(context).pop();

+ 2 - 5
lib/ui/sharing/share_collection_page.dart

@@ -207,11 +207,8 @@ class _ShareCollectionPageState extends State<ShareCollectionPage> {
           menuItemColor: getEnteColorScheme(context).fillFaint,
           pressedColor: getEnteColorScheme(context).fillFaint,
           onTap: () async {
-            final bool result = await collectionActions.publicLinkToggle(
-              context,
-              widget.collection,
-              true,
-            );
+            final bool result =
+                await collectionActions.enableUrl(context, widget.collection);
             if (result && mounted) {
               setState(() => {});
             }