DEV: Add gjs implementation of solved topic status (#327)

This commit is contained in:
Jarek Radosz 2025-01-14 13:38:48 +01:00 committed by GitHub
parent 3f724bf311
commit a73bfa228e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 78 additions and 33 deletions

View File

@ -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

View File

@ -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>
}

View File

@ -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";
@ -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",
@ -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);