2
0
Эх сурвалжийг харах

create a function for generating a button

kaori 5 жил өмнө
parent
commit
e80a16b451
1 өөрчлөгдсөн 15 нэмэгдсэн , 18 устгасан
  1. 15 18
      src/server/service/bolt.js

+ 15 - 18
src/server/service/bolt.js

@@ -219,24 +219,8 @@ class BoltService {
           {
             type: 'actions',
             elements: [
-              {
-                type: 'button',
-                text: {
-                  type: 'plain_text',
-                  text: 'Next',
-                },
-                action_id: 'showNextResults',
-              },
-              {
-                type: 'button',
-                text: {
-                  type: 'plain_text',
-                  text: 'Share',
-                },
-                style: 'primary',
-                action_id: 'shareSearchResults',
-                value: `${keywordsAndDesc} \n\n ${urls.join('\n')}`,
-              },
+              this.generateButtonBlock('Next', 'showNextResults'),
+              this.generateButtonBlock('Share', 'shareSearchResults', 'primary', `${keywordsAndDesc} \n\n ${urls.join('\n')}`),
             ],
           },
         ],
@@ -341,6 +325,19 @@ class BoltService {
     }
   }
 
+  generateButtonBlock(text, actionId, style, value) {
+    return {
+      type: 'button',
+      text: {
+        type: 'plain_text',
+        text,
+      },
+      style,
+      action_id: actionId,
+      value,
+    };
+  }
+
   generateMarkdownSectionBlock(blocks) {
     return {
       type: 'section',