From a92fcfdd5825d8cacb4ba6fb15995b83d351f7b7 Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 8 Mar 2023 21:40:38 +0200 Subject: [PATCH 1/2] UX: Tweak 'Solution' button design --- .../initializers/extend-for-solved-button.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js b/assets/javascripts/discourse/initializers/extend-for-solved-button.js index e0173fa4..3e18fb19 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js @@ -90,8 +90,6 @@ function initializeWithApi(api) { 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"; if (canAccept) { return { @@ -99,8 +97,8 @@ function initializeWithApi(api) { icon: "far-check-square", className: "unaccepted", title: "solved.accept_answer", - label: "solved.solution", - position, + label: isOp ? "solved.solution" : null, + position: isOp ? "first" : "second", }; } else if (canUnaccept && accepted) { const title = canUnaccept @@ -111,14 +109,14 @@ function initializeWithApi(api) { icon: "check-square", title, className: "accepted fade-out", - position, - label: "solved.solution", + position: isOp ? "first" : "second", + label: isOp ? "solved.solution" : null, }; } else if (!canAccept && accepted) { return { className: "hidden", disabled: "true", - position, + position: "first", beforeButton(h) { return h( "span.accepted-text", From e1730ddd7353219f504489ec919ff6bb679550cb Mon Sep 17 00:00:00 2001 From: Bianca Nenciu Date: Wed, 8 Mar 2023 21:58:19 +0200 Subject: [PATCH 2/2] DEV: Apply code suggestions --- .../initializers/extend-for-solved-button.js | 66 +++++++++---------- 1 file changed, 31 insertions(+), 35 deletions(-) diff --git a/assets/javascripts/discourse/initializers/extend-for-solved-button.js b/assets/javascripts/discourse/initializers/extend-for-solved-button.js index 3e18fb19..e3d4e909 100644 --- a/assets/javascripts/discourse/initializers/extend-for-solved-button.js +++ b/assets/javascripts/discourse/initializers/extend-for-solved-button.js @@ -86,12 +86,9 @@ 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 isOp = currentUser?.id === attrs.topicCreatedById; - if (canAccept) { + if (attrs.can_accept_answer) { return { action: "acceptAnswer", icon: "far-check-square", @@ -100,36 +97,35 @@ function initializeWithApi(api) { label: isOp ? "solved.solution" : null, position: isOp ? "first" : "second", }; - } 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: isOp ? "first" : "second", - label: isOp ? "solved.solution" : null, - }; - } else if (!canAccept && accepted) { - 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")), - ] - ); - }, - }; + } 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")), + ] + ); + }, + }; + } } });