UX: Tweak 'Solution' button design (#232)
Hide the accept solution button if a solution has been accepted already.
This commit is contained in:
parent
ee55e6d160
commit
4ae1841479
|
@ -19,6 +19,7 @@ function clearAccepted(topic) {
|
||||||
accepted_answer: false,
|
accepted_answer: false,
|
||||||
can_accept_answer: true,
|
can_accept_answer: true,
|
||||||
can_unaccept_answer: false,
|
can_unaccept_answer: false,
|
||||||
|
topic_accepted_answer: false,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -78,7 +79,8 @@ function initializeWithApi(api) {
|
||||||
api.includePostAttributes(
|
api.includePostAttributes(
|
||||||
"can_accept_answer",
|
"can_accept_answer",
|
||||||
"can_unaccept_answer",
|
"can_unaccept_answer",
|
||||||
"accepted_answer"
|
"accepted_answer",
|
||||||
|
"topic_accepted_answer"
|
||||||
);
|
);
|
||||||
|
|
||||||
if (api.addDiscoveryQueryParam) {
|
if (api.addDiscoveryQueryParam) {
|
||||||
|
@ -86,16 +88,16 @@ function initializeWithApi(api) {
|
||||||
}
|
}
|
||||||
|
|
||||||
api.addPostMenuButton("solved", (attrs) => {
|
api.addPostMenuButton("solved", (attrs) => {
|
||||||
|
if (attrs.can_accept_answer) {
|
||||||
const isOp = currentUser?.id === attrs.topicCreatedById;
|
const isOp = currentUser?.id === attrs.topicCreatedById;
|
||||||
|
|
||||||
if (attrs.can_accept_answer) {
|
|
||||||
return {
|
return {
|
||||||
action: "acceptAnswer",
|
action: "acceptAnswer",
|
||||||
icon: "far-check-square",
|
icon: "far-check-square",
|
||||||
className: "unaccepted",
|
className: "unaccepted",
|
||||||
title: "solved.accept_answer",
|
title: "solved.accept_answer",
|
||||||
label: isOp ? "solved.solution" : null,
|
label: isOp ? "solved.solution" : null,
|
||||||
position: isOp ? "first" : "second",
|
position: attrs.topic_accepted_answer ? "second-last-hidden" : "first",
|
||||||
};
|
};
|
||||||
} else if (attrs.accepted_answer) {
|
} else if (attrs.accepted_answer) {
|
||||||
if (attrs.can_unaccept_answer) {
|
if (attrs.can_unaccept_answer) {
|
||||||
|
@ -104,8 +106,8 @@ function initializeWithApi(api) {
|
||||||
icon: "check-square",
|
icon: "check-square",
|
||||||
title: "solved.unaccept_answer",
|
title: "solved.unaccept_answer",
|
||||||
className: "accepted fade-out",
|
className: "accepted fade-out",
|
||||||
position: isOp ? "first" : "second",
|
position: "first",
|
||||||
label: isOp ? "solved.solution" : null,
|
label: "solved.solution",
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
return {
|
return {
|
||||||
|
@ -168,23 +170,22 @@ function initializeWithApi(api) {
|
||||||
|
|
||||||
api.attachWidgetAction("post", "acceptAnswer", function () {
|
api.attachWidgetAction("post", "acceptAnswer", function () {
|
||||||
const post = this.model;
|
const post = this.model;
|
||||||
const current = post.get("topic.postStream.posts").filter((p) => {
|
|
||||||
return p.post_number === 1 || p.accepted_answer;
|
|
||||||
});
|
|
||||||
acceptPost(post);
|
acceptPost(post);
|
||||||
|
|
||||||
current.forEach((p) =>
|
post.get("topic.postStream.posts").forEach((p) => {
|
||||||
this.appEvents.trigger("post-stream:refresh", { id: p.id })
|
p.set("topic_accepted_answer", true);
|
||||||
);
|
this.appEvents.trigger("post-stream:refresh", { id: p.id });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
api.attachWidgetAction("post", "unacceptAnswer", function () {
|
api.attachWidgetAction("post", "unacceptAnswer", function () {
|
||||||
const post = this.model;
|
const post = this.model;
|
||||||
const op = post
|
|
||||||
.get("topic.postStream.posts")
|
|
||||||
.find((p) => p.post_number === 1);
|
|
||||||
unacceptPost(post);
|
unacceptPost(post);
|
||||||
this.appEvents.trigger("post-stream:refresh", { id: op.id });
|
|
||||||
|
post.get("topic.postStream.posts").forEach((p) => {
|
||||||
|
p.set("topic_accepted_answer", false);
|
||||||
|
this.appEvents.trigger("post-stream:refresh", { id: p.id });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
if (api.registerConnectorClass) {
|
if (api.registerConnectorClass) {
|
||||||
|
|
|
@ -504,7 +504,7 @@ SQL
|
||||||
|
|
||||||
require_dependency "post_serializer"
|
require_dependency "post_serializer"
|
||||||
class ::PostSerializer
|
class ::PostSerializer
|
||||||
attributes :can_accept_answer, :can_unaccept_answer, :accepted_answer
|
attributes :can_accept_answer, :can_unaccept_answer, :accepted_answer, :topic_accepted_answer
|
||||||
|
|
||||||
def can_accept_answer
|
def can_accept_answer
|
||||||
if topic = (topic_view && topic_view.topic) || object.topic
|
if topic = (topic_view && topic_view.topic) || object.topic
|
||||||
|
@ -524,6 +524,12 @@ SQL
|
||||||
def accepted_answer
|
def accepted_answer
|
||||||
post_custom_fields["is_accepted_answer"] == "true"
|
post_custom_fields["is_accepted_answer"] == "true"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def topic_accepted_answer
|
||||||
|
if topic = (topic_view && topic_view.topic) || object.topic
|
||||||
|
topic.custom_fields["accepted_answer_post_id"].present?
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require_dependency "search"
|
require_dependency "search"
|
||||||
|
|
Loading…
Reference in New Issue