DEV: Remove the legacy widget post menu code (#351)

This commit is contained in:
Sérgio Saquetim 2025-04-02 18:31:40 -03:00 committed by GitHub
parent 390141297f
commit b128e65ae5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 81 deletions

View File

@ -19,7 +19,16 @@ export default class SolvedAcceptAnswerButton extends Component {
@action
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>
@ -34,18 +43,6 @@ export default class SolvedAcceptAnswerButton extends Component {
</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) {
const topic = post.topic;

View File

@ -10,18 +10,6 @@ import { formatUsername } from "discourse/lib/utilities";
import { i18n } from "discourse-i18n";
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) {
if (!post.can_unaccept_answer) {
return;
@ -48,7 +36,16 @@ export default class SolvedUnacceptAnswerButton extends Component {
@action
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() {

View File

@ -1,7 +1,7 @@
import { computed } from "@ember/object";
import discourseComputed from "discourse/lib/decorators";
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 { formatUsername } from "discourse/lib/utilities";
import Topic from "discourse/models/topic";
@ -72,7 +72,7 @@ function initializeWithApi(api) {
}
function customizePostMenu(api) {
const transformerRegistered = api.registerValueTransformer(
api.registerValueTransformer(
"post-menu-buttons",
({
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 {