From 7ea62738c5276d7ac28a6e53724e731b3e7dd354 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Thu, 9 Mar 2023 10:33:06 +0200 Subject: [PATCH] UX: Tweak 'Solution' button design (#230) --- .../initializers/extend-for-solved-button.js | 72 +++++++++---------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js b/assets/javascripts/discourse/initializers/extend-for-solved-button.js index e0173fa..e3d4e90 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js @@ -86,52 +86,46 @@ function initializeWithApi(api) { } api.addPostMenuButton("solved", (attrs) => { - const canAccept = attrs.can_accept_answer; - const canUnaccept = attrs.can_unaccept_answer; - const accepted = attrs.accepted_answer; - const isOp = currentUser && currentUser.id === attrs.topicCreatedById; - const position = - !accepted && canAccept && !isOp ? "second-last-hidden" : "first"; + const isOp = currentUser?.id === attrs.topicCreatedById; - if (canAccept) { + if (attrs.can_accept_answer) { return { action: "acceptAnswer", icon: "far-check-square", className: "unaccepted", title: "solved.accept_answer", - label: "solved.solution", - position, - }; - } else if (canUnaccept && accepted) { - const title = canUnaccept - ? "solved.unaccept_answer" - : "solved.accepted_answer"; - return { - action: "unacceptAnswer", - icon: "check-square", - title, - className: "accepted fade-out", - position, - label: "solved.solution", - }; - } else if (!canAccept && accepted) { - return { - className: "hidden", - disabled: "true", - position, - beforeButton(h) { - return h( - "span.accepted-text", - { - title: I18n.t("solved.accepted_description"), - }, - [ - h("span", iconNode("check")), - h("span.accepted-label", I18n.t("solved.solution")), - ] - ); - }, + label: isOp ? "solved.solution" : null, + position: isOp ? "first" : "second", }; + } else if (attrs.accepted_answer) { + if (attrs.can_unaccept_answer) { + return { + action: "unacceptAnswer", + icon: "check-square", + title: "solved.unaccept_answer", + className: "accepted fade-out", + position: isOp ? "first" : "second", + label: isOp ? "solved.solution" : null, + }; + } else { + return { + className: "hidden", + disabled: "true", + position: "first", + beforeButton(h) { + return h( + "span.accepted-text", + { + title: I18n.t("solved.accepted_description"), + }, + [ + h("span", iconNode("check")), + h("span.accepted-label", I18n.t("solved.solution")), + ] + ); + }, + }; + } } });