Skip to content

Commit

Permalink
DEV: Add gjs implementation of solved topic status (#327)
Browse files Browse the repository at this point in the history
  • Loading branch information
CvX authored Jan 14, 2025
1 parent 3f724bf commit a73bfa2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 33 deletions.
1 change: 1 addition & 0 deletions .discourse-compatibility
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
< 3.4.0.beta4-dev: 3f724bf3114cc7877fa757bc8035f13a7390c739
< 3.4.0.beta2-dev: 1bbdfd8f5681171dc3f0e9ea93cd56997dc7938a
< 3.4.0.beta1-dev: dc1ef92be23332a54854751a23b9029463584845
< 3.3.0.beta2-dev: a18ce6d712fafed286bcc99543dd173110c6dfb8
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import Component from "@glimmer/component";
import { service } from "@ember/service";
import { and } from "truth-helpers";
import icon from "discourse/helpers/d-icon";
import { i18n } from "discourse-i18n";

export default class SolvedStatus extends Component {
@service siteSettings;

<template>
{{~#if @outletArgs.topic.has_accepted_answer~}}
<span
title={{i18n "topic_statuses.solved.help"}}
class="topic-status"
>{{icon "far-square-check"}}</span>
{{~else if
(and
@outletArgs.topic.can_have_answer
this.siteSettings.solved_enabled
this.siteSettings.empty_box_on_unsolved
)
~}}
<span
title={{i18n "solved.has_no_accepted_answer"}}
class="topic-status"
>{{icon "far-square"}}</span>
{{~/if~}}
</template>
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { computed } from "@ember/object";
import TopicStatusIcons from "discourse/helpers/topic-status-icons";
import discourseComputed from "discourse/lib/decorators";
import { withPluginApi } from "discourse/lib/plugin-api";
import { formatUsername } from "discourse/lib/utilities";
import Topic from "discourse/models/topic";
import User from "discourse/models/user";
import TopicStatus from "discourse/raw-views/topic-status";
import PostCooked from "discourse/widgets/post-cooked";
import { withSilencedDeprecations } from "discourse-common/lib/deprecated";
import { iconHTML, iconNode } from "discourse-common/lib/icon-library";
Expand All @@ -19,12 +18,6 @@ import SolvedUnacceptAnswerButton, {
function initializeWithApi(api) {
customizePostMenu(api);

TopicStatusIcons.addObject([
"has_accepted_answer",
"far-square-check",
"solved",
]);

api.includePostAttributes(
"can_accept_answer",
"can_unaccept_answer",
Expand Down Expand Up @@ -205,32 +198,54 @@ export default {
}),
});

TopicStatus.reopen({
statuses: computed(function () {
const results = this._super(...arguments);
withPluginApi("2.0.0", (api) => {
withSilencedDeprecations("discourse.hbr-topic-list-overrides", () => {
let topicStatusIcons;
try {
topicStatusIcons =
require("discourse/helpers/topic-status-icons").default;
} catch {}

if (this.topic.has_accepted_answer) {
results.push({
openTag: "span",
closeTag: "span",
title: i18n("topic_statuses.solved.help"),
icon: "far-square-check",
key: "solved",
});
} else if (
this.topic.can_have_answer &&
this.siteSettings.solved_enabled &&
this.siteSettings.empty_box_on_unsolved
) {
results.push({
openTag: "span",
closeTag: "span",
title: i18n("solved.has_no_accepted_answer"),
icon: "far-square",
});
}
return results;
}),
topicStatusIcons?.addObject([
"has_accepted_answer",
"far-square-check",
"solved",
]);

api.modifyClass(
"raw-view:topic-status",
(Superclass) =>
class extends Superclass {
@discourseComputed("topic.{has_accepted_answer,can_have_answer}")
statuses() {
const results = super.statuses;

if (this.topic.has_accepted_answer) {
results.push({
openTag: "span",
closeTag: "span",
title: i18n("topic_statuses.solved.help"),
icon: "far-square-check",
key: "solved",
});
} else if (
this.topic.can_have_answer &&
this.siteSettings.solved_enabled &&
this.siteSettings.empty_box_on_unsolved
) {
results.push({
openTag: "span",
closeTag: "span",
title: i18n("solved.has_no_accepted_answer"),
icon: "far-square",
});
}

return results;
}
}
);
});
});

withPluginApi("1.34.0", initializeWithApi);
Expand Down

0 comments on commit a73bfa2

Please sign in to comment.