UX: Tweak 'Solution' button design (#230)

This commit is contained in:
Bianca Nenciu 2023-03-09 10:33:06 +02:00 committed by GitHub
parent 2c1c64af2b
commit 7ea62738c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 33 additions and 39 deletions

View File

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