DEV: Refactor buttonTitle (#61)

DEV: Refactor buttonTitle (#61)

Should be a tiny bit easier to follow now.

diff --git a/assets/javascripts/discourse/widgets/vote-button.js.es6 b/assets/javascripts/discourse/widgets/vote-button.js.es6
index e880905..638331a 100644
--- a/assets/javascripts/discourse/widgets/vote-button.js.es6
+++ b/assets/javascripts/discourse/widgets/vote-button.js.es6
@@ -26,33 +26,33 @@ export default createWidget("vote-button", {
     return buttonClass;
   },
 
-  html(attrs) {
-    let buttonTitle;
+  buildButtonTitle(attrs) {
+    if (this.currentUser) {
+      if (attrs.closed) {
+        return I18n.t("voting.voting_closed_title");
+      }
 
-    if (!this.currentUser) {
-      if (attrs.vote_count) {
-        buttonTitle = I18n.t("voting.anonymous_button", {
-          count: attrs.vote_count,
-        });
-      } else {
-        buttonTitle = I18n.t("voting.anonymous_button", { count: 1 });
+      if (attrs.user_voted) {
+        return I18n.t("voting.voted_title");
       }
-    } else {
-      if (attrs.closed) {
-        buttonTitle = I18n.t("voting.voting_closed_title");
-      } else {
-        if (attrs.user_voted) {
-          buttonTitle = I18n.t("voting.voted_title");
-        } else {
-          if (this.currentUser && this.currentUser.votes_exceeded) {
-            buttonTitle = I18n.t("voting.voting_limit");
-          } else {
-            buttonTitle = I18n.t("voting.vote_title");
-          }
-        }
+
+      if (this.currentUser.votes_exceeded) {
+        return I18n.t("voting.voting_limit");
       }
+
+      return I18n.t("voting.vote_title");
+    }
+
+    if (attrs.vote_count) {
+      return I18n.t("voting.anonymous_button", {
+        count: attrs.vote_count,
+      });
     }
 
+    return I18n.t("voting.anonymous_button", { count: 1 });
+  },
+
+  html(attrs) {
     return h(
       "button",
       {
@@ -65,7 +65,7 @@ export default createWidget("vote-button", {
         },
         className: "btn btn-primary vote-button",
       },
-      buttonTitle
+      this.buildButtonTitle(attrs)
     );
   },
 

GitHub sha: 864cf465

This commit appears in #61 which was approved by jjaffeux. It was merged by CvX.