Skip to content

Commit

Permalink
UX: Tweak 'Solution' button design (#230)
Browse files Browse the repository at this point in the history
  • Loading branch information
nbianca committed Mar 9, 2023
1 parent 2c1c64a commit 7ea6273
Showing 1 changed file with 34 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";

if (canAccept) {
const isOp = currentUser?.id === attrs.topicCreatedById;

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")),
]
);
},
};
}
}
});

Expand Down

0 comments on commit 7ea6273

Please sign in to comment.