FEATURE: uses new topic footer button api (#5)

FEATURE: uses new topic footer button api (#5)

diff --git a/assets/javascripts/discourse/initializers/init-code-review.js.es6 b/assets/javascripts/discourse/initializers/init-code-review.js.es6
index 216dbee..fcffde2 100644
--- a/assets/javascripts/discourse/initializers/init-code-review.js.es6
+++ b/assets/javascripts/discourse/initializers/init-code-review.js.es6
@@ -82,68 +82,41 @@ function initialize(api) {
     );
   }
 
-  api
-    .modifySelectKit("topic-footer-mobile-dropdown")
-    .modifyContent((context, existingContent) => {
-      const topic = context.get("topic");
-
-      if (allowUser()) {
-        if (allowApprove(topic))
-          existingContent.push({
-            id: "approve",
-            icon: "thumbs-up",
-            name: I18n.t("code_review.approve.label")
-          });
-
-        if (allowFollowup(topic))
-          existingContent.push({
-            id: "followup",
-            icon: "clock-o",
-            name: I18n.t("code_review.followup.label")
-          });
-      }
-      return existingContent;
-    })
-    .onSelect((context, value) => {
-      if (value === "approve" || value === "followup") {
-        const topic = context.get("topic");
-        actOnCommit(topic, value);
-        return true;
-      }
-    });
-
-  api.registerConnectorClass(
-    "topic-footer-main-buttons-before-create",
-    "approve",
-    {
-      setupComponent(args) {
-        this.set("topic", args.topic);
-        this.set("showApprove", allowApprove(args.topic));
-        this.set("showFollowup", allowFollowup(args.topic));
-      },
-      shouldRender: function(args, component) {
-        if (component.get("site.mobileView")) {
-          return false;
-        }
-        return allowUser(args.topic);
-      },
-
-      actions: {
-        followupCommit() {
-          actOnCommit(this.get("topic"), "followup");
-        },
-        approveCommit() {
-          actOnCommit(this.get("topic"), "approve");
-        }
-      }
+  api.registerTopicFooterButton({
+    id: "approve",
+    icon: "thumbs-up",
+    priority: 250,
+    label: "code_review.approve.label",
+    title: "code_review.approve.title",
+    action() { actOnCommit(this.get("topic"), "approve"); },
+    dropdown() { return this.site.movileView; },
+    classNames: ["approve"],
+    dependentKeys: ["topic.tags"],
+    displayed() {
+      return allowUser() && allowApprove(this.get("topic"));
     }
-  );
+  });
+
+  api.registerTopicFooterButton({
+    id: "followup",
+    icon: "clock-o",
+    priority: 250,
+    label: "code_review.followup.label",
+    title: "code_review.followup.title",
+    action() { actOnCommit(this.get("topic"), "followup"); },
+    dropdown() { return this.site.movileView; },
+    classNames: ["followup"],
+    dependentKeys: ["topic.tags"],
+    displayed() {
+      return allowUser() && allowFollowup(this.get("topic"));
+    }
+  });
 }
 
 export default {
   name: "discourse-code-review",
 
   initialize() {
-    withPluginApi("0.8.7", initialize);
+    withPluginApi("0.8.28", initialize);
   }
 };
diff --git a/assets/javascripts/discourse/templates/connectors/topic-footer-main-buttons-before-create/approve.hbs b/assets/javascripts/discourse/templates/connectors/topic-footer-main-buttons-before-create/approve.hbs
deleted file mode 100644
index b751bff..0000000
--- a/assets/javascripts/discourse/templates/connectors/topic-footer-main-buttons-before-create/approve.hbs
+++ /dev/null
@@ -1,17 +0,0 @@
-{{#if showApprove}}
-{{d-button
-  class="btn approve-commit-button"
-  title="code_review.approve.title"
-  label="code_review.approve.label"
-  icon="thumbs-up"
-  action="approveCommit"}}
-{{/if}}
-
-{{#if showFollowup}}
-{{d-button
-  class="btn follow-up-commit-button"
-  title="code_review.followup.title"
-  label="code_review.followup.label"
-  icon="clock-o"
-  action="followupCommit"}}
-{{/if}}

GitHub sha: 65e10d08

1 Like