mirror of
https://github.com/discourse/discourse-solved.git
synced 2025-05-03 12:44:55 +00:00
DEV: Remove the legacy widget post menu code (#351)
This commit is contained in:
parent
390141297f
commit
b128e65ae5
@ -19,7 +19,16 @@ export default class SolvedAcceptAnswerButton extends Component {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
acceptAnswer() {
|
acceptAnswer() {
|
||||||
acceptAnswer(this.args.post, this.appEvents, this.currentUser);
|
const post = this.args.post;
|
||||||
|
|
||||||
|
acceptPost(post, this.currentUser);
|
||||||
|
|
||||||
|
this.appEvents.trigger("discourse-solved:solution-toggled", post);
|
||||||
|
|
||||||
|
post.get("topic.postStream.posts").forEach((p) => {
|
||||||
|
p.set("topic_accepted_answer", true);
|
||||||
|
this.appEvents.trigger("post-stream:refresh", { id: p.id });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
@ -34,18 +43,6 @@ export default class SolvedAcceptAnswerButton extends Component {
|
|||||||
</template>
|
</template>
|
||||||
}
|
}
|
||||||
|
|
||||||
export function acceptAnswer(post, appEvents, acceptingUser) {
|
|
||||||
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
|
|
||||||
acceptPost(post, acceptingUser);
|
|
||||||
|
|
||||||
appEvents.trigger("discourse-solved:solution-toggled", post);
|
|
||||||
|
|
||||||
post.get("topic.postStream.posts").forEach((p) => {
|
|
||||||
p.set("topic_accepted_answer", true);
|
|
||||||
appEvents.trigger("post-stream:refresh", { id: p.id });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function acceptPost(post, acceptingUser) {
|
function acceptPost(post, acceptingUser) {
|
||||||
const topic = post.topic;
|
const topic = post.topic;
|
||||||
|
|
||||||
|
@ -10,18 +10,6 @@ import { formatUsername } from "discourse/lib/utilities";
|
|||||||
import { i18n } from "discourse-i18n";
|
import { i18n } from "discourse-i18n";
|
||||||
import DTooltip from "float-kit/components/d-tooltip";
|
import DTooltip from "float-kit/components/d-tooltip";
|
||||||
|
|
||||||
export function unacceptAnswer(post, appEvents) {
|
|
||||||
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
|
|
||||||
unacceptPost(post);
|
|
||||||
|
|
||||||
appEvents.trigger("discourse-solved:solution-toggled", post);
|
|
||||||
|
|
||||||
post.get("topic.postStream.posts").forEach((p) => {
|
|
||||||
p.set("topic_accepted_answer", false);
|
|
||||||
appEvents.trigger("post-stream:refresh", { id: p.id });
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function unacceptPost(post) {
|
function unacceptPost(post) {
|
||||||
if (!post.can_unaccept_answer) {
|
if (!post.can_unaccept_answer) {
|
||||||
return;
|
return;
|
||||||
@ -48,7 +36,16 @@ export default class SolvedUnacceptAnswerButton extends Component {
|
|||||||
|
|
||||||
@action
|
@action
|
||||||
unacceptAnswer() {
|
unacceptAnswer() {
|
||||||
unacceptAnswer(this.args.post, this.appEvents);
|
const post = this.args.post;
|
||||||
|
|
||||||
|
unacceptPost(post);
|
||||||
|
|
||||||
|
this.appEvents.trigger("discourse-solved:solution-toggled", post);
|
||||||
|
|
||||||
|
post.get("topic.postStream.posts").forEach((p) => {
|
||||||
|
p.set("topic_accepted_answer", false);
|
||||||
|
this.appEvents.trigger("post-stream:refresh", { id: p.id });
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
get solvedBy() {
|
get solvedBy() {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { computed } from "@ember/object";
|
import { computed } from "@ember/object";
|
||||||
import discourseComputed from "discourse/lib/decorators";
|
import discourseComputed from "discourse/lib/decorators";
|
||||||
import { withSilencedDeprecations } from "discourse/lib/deprecated";
|
import { withSilencedDeprecations } from "discourse/lib/deprecated";
|
||||||
import { iconHTML, iconNode } from "discourse/lib/icon-library";
|
import { iconHTML } from "discourse/lib/icon-library";
|
||||||
import { withPluginApi } from "discourse/lib/plugin-api";
|
import { withPluginApi } from "discourse/lib/plugin-api";
|
||||||
import { formatUsername } from "discourse/lib/utilities";
|
import { formatUsername } from "discourse/lib/utilities";
|
||||||
import Topic from "discourse/models/topic";
|
import Topic from "discourse/models/topic";
|
||||||
@ -72,7 +72,7 @@ function initializeWithApi(api) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function customizePostMenu(api) {
|
function customizePostMenu(api) {
|
||||||
const transformerRegistered = api.registerValueTransformer(
|
api.registerValueTransformer(
|
||||||
"post-menu-buttons",
|
"post-menu-buttons",
|
||||||
({
|
({
|
||||||
value: dag,
|
value: dag,
|
||||||
@ -109,59 +109,6 @@ function customizePostMenu(api) {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const silencedKey =
|
|
||||||
transformerRegistered && "discourse.post-menu-widget-overrides";
|
|
||||||
|
|
||||||
withSilencedDeprecations(silencedKey, () => customizeWidgetPostMenu(api));
|
|
||||||
}
|
|
||||||
|
|
||||||
function customizeWidgetPostMenu(api) {
|
|
||||||
const currentUser = api.getCurrentUser();
|
|
||||||
|
|
||||||
api.addPostMenuButton("solved", (attrs) => {
|
|
||||||
if (attrs.can_accept_answer) {
|
|
||||||
const isOp = currentUser?.id === attrs.topicCreatedById;
|
|
||||||
|
|
||||||
return {
|
|
||||||
action: "acceptAnswer",
|
|
||||||
icon: "far-square-check",
|
|
||||||
className: "unaccepted",
|
|
||||||
title: "solved.accept_answer",
|
|
||||||
label: isOp ? "solved.solution" : null,
|
|
||||||
position: attrs.topic_accepted_answer ? "second-last-hidden" : "first",
|
|
||||||
};
|
|
||||||
} else if (attrs.accepted_answer) {
|
|
||||||
if (attrs.can_unaccept_answer) {
|
|
||||||
return {
|
|
||||||
action: "unacceptAnswer",
|
|
||||||
icon: "square-check",
|
|
||||||
title: "solved.unaccept_answer",
|
|
||||||
className: "accepted fade-out",
|
|
||||||
position: "first",
|
|
||||||
label: "solved.solution",
|
|
||||||
};
|
|
||||||
} else {
|
|
||||||
return {
|
|
||||||
className: "hidden",
|
|
||||||
disabled: "true",
|
|
||||||
position: "first",
|
|
||||||
beforeButton(h) {
|
|
||||||
return h(
|
|
||||||
"span.accepted-text",
|
|
||||||
{
|
|
||||||
title: i18n("solved.accepted_description"),
|
|
||||||
},
|
|
||||||
[
|
|
||||||
h("span", iconNode("check")),
|
|
||||||
h("span.accepted-label", i18n("solved.solution")),
|
|
||||||
]
|
|
||||||
);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user