Skip to content

Commit b128e65

Browse files
authored
DEV: Remove the legacy widget post menu code (#351)
1 parent 3901412 commit b128e65

File tree

3 files changed

+22
-81
lines changed

3 files changed

+22
-81
lines changed

assets/javascripts/discourse/components/solved-accept-answer-button.gjs

+10-13
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,16 @@ export default class SolvedAcceptAnswerButton extends Component {
1919

2020
@action
2121
acceptAnswer() {
22-
acceptAnswer(this.args.post, this.appEvents, this.currentUser);
22+
const post = this.args.post;
23+
24+
acceptPost(post, this.currentUser);
25+
26+
this.appEvents.trigger("discourse-solved:solution-toggled", post);
27+
28+
post.get("topic.postStream.posts").forEach((p) => {
29+
p.set("topic_accepted_answer", true);
30+
this.appEvents.trigger("post-stream:refresh", { id: p.id });
31+
});
2332
}
2433

2534
<template>
@@ -34,18 +43,6 @@ export default class SolvedAcceptAnswerButton extends Component {
3443
</template>
3544
}
3645

37-
export function acceptAnswer(post, appEvents, acceptingUser) {
38-
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
39-
acceptPost(post, acceptingUser);
40-
41-
appEvents.trigger("discourse-solved:solution-toggled", post);
42-
43-
post.get("topic.postStream.posts").forEach((p) => {
44-
p.set("topic_accepted_answer", true);
45-
appEvents.trigger("post-stream:refresh", { id: p.id });
46-
});
47-
}
48-
4946
function acceptPost(post, acceptingUser) {
5047
const topic = post.topic;
5148

assets/javascripts/discourse/components/solved-unaccept-answer-button.gjs

+10-13
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ import { formatUsername } from "discourse/lib/utilities";
1010
import { i18n } from "discourse-i18n";
1111
import DTooltip from "float-kit/components/d-tooltip";
1212

13-
export function unacceptAnswer(post, appEvents) {
14-
// TODO (glimmer-post-menu): Remove this exported function and move the code into the button action after the widget code is removed
15-
unacceptPost(post);
16-
17-
appEvents.trigger("discourse-solved:solution-toggled", post);
18-
19-
post.get("topic.postStream.posts").forEach((p) => {
20-
p.set("topic_accepted_answer", false);
21-
appEvents.trigger("post-stream:refresh", { id: p.id });
22-
});
23-
}
24-
2513
function unacceptPost(post) {
2614
if (!post.can_unaccept_answer) {
2715
return;
@@ -48,7 +36,16 @@ export default class SolvedUnacceptAnswerButton extends Component {
4836

4937
@action
5038
unacceptAnswer() {
51-
unacceptAnswer(this.args.post, this.appEvents);
39+
const post = this.args.post;
40+
41+
unacceptPost(post);
42+
43+
this.appEvents.trigger("discourse-solved:solution-toggled", post);
44+
45+
post.get("topic.postStream.posts").forEach((p) => {
46+
p.set("topic_accepted_answer", false);
47+
this.appEvents.trigger("post-stream:refresh", { id: p.id });
48+
});
5249
}
5350

5451
get solvedBy() {

assets/javascripts/discourse/initializers/extend-for-solved-button.js

+2-55
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { computed } from "@ember/object";
22
import discourseComputed from "discourse/lib/decorators";
33
import { withSilencedDeprecations } from "discourse/lib/deprecated";
4-
import { iconHTML, iconNode } from "discourse/lib/icon-library";
4+
import { iconHTML } from "discourse/lib/icon-library";
55
import { withPluginApi } from "discourse/lib/plugin-api";
66
import { formatUsername } from "discourse/lib/utilities";
77
import Topic from "discourse/models/topic";
@@ -72,7 +72,7 @@ function initializeWithApi(api) {
7272
}
7373

7474
function customizePostMenu(api) {
75-
const transformerRegistered = api.registerValueTransformer(
75+
api.registerValueTransformer(
7676
"post-menu-buttons",
7777
({
7878
value: dag,
@@ -109,59 +109,6 @@ function customizePostMenu(api) {
109109
);
110110
}
111111
);
112-
113-
const silencedKey =
114-
transformerRegistered && "discourse.post-menu-widget-overrides";
115-
116-
withSilencedDeprecations(silencedKey, () => customizeWidgetPostMenu(api));
117-
}
118-
119-
function customizeWidgetPostMenu(api) {
120-
const currentUser = api.getCurrentUser();
121-
122-
api.addPostMenuButton("solved", (attrs) => {
123-
if (attrs.can_accept_answer) {
124-
const isOp = currentUser?.id === attrs.topicCreatedById;
125-
126-
return {
127-
action: "acceptAnswer",
128-
icon: "far-square-check",
129-
className: "unaccepted",
130-
title: "solved.accept_answer",
131-
label: isOp ? "solved.solution" : null,
132-
position: attrs.topic_accepted_answer ? "second-last-hidden" : "first",
133-
};
134-
} else if (attrs.accepted_answer) {
135-
if (attrs.can_unaccept_answer) {
136-
return {
137-
action: "unacceptAnswer",
138-
icon: "square-check",
139-
title: "solved.unaccept_answer",
140-
className: "accepted fade-out",
141-
position: "first",
142-
label: "solved.solution",
143-
};
144-
} else {
145-
return {
146-
className: "hidden",
147-
disabled: "true",
148-
position: "first",
149-
beforeButton(h) {
150-
return h(
151-
"span.accepted-text",
152-
{
153-
title: i18n("solved.accepted_description"),
154-
},
155-
[
156-
h("span", iconNode("check")),
157-
h("span.accepted-label", i18n("solved.solution")),
158-
]
159-
);
160-
},
161-
};
162-
}
163-
}
164-
});
165112
}
166113

167114
export default {

0 commit comments

Comments
 (0)