From dd329d55a52fab88ac2ac286c5a0629da0c8d105 Mon Sep 17 00:00:00 2001 From: Jarek Radosz Date: Thu, 20 Jun 2024 10:17:29 +0200 Subject: [PATCH] DEV: Convert topic-status to glimmer/gjs (#27536) Now that discourse-moderator-attention is gone this is safe to change. --- .../discourse/app/components/topic-status.gjs | 105 ++++++++++++++++++ .../discourse/app/components/topic-status.hbs | 69 ------------ .../discourse/app/components/topic-status.js | 104 ----------------- 3 files changed, 105 insertions(+), 173 deletions(-) create mode 100644 app/assets/javascripts/discourse/app/components/topic-status.gjs delete mode 100644 app/assets/javascripts/discourse/app/components/topic-status.hbs delete mode 100644 app/assets/javascripts/discourse/app/components/topic-status.js diff --git a/app/assets/javascripts/discourse/app/components/topic-status.gjs b/app/assets/javascripts/discourse/app/components/topic-status.gjs new file mode 100644 index 00000000000..3eacdd3cd50 --- /dev/null +++ b/app/assets/javascripts/discourse/app/components/topic-status.gjs @@ -0,0 +1,105 @@ +import Component from "@glimmer/component"; +import { hash } from "@ember/helper"; +import { on } from "@ember/modifier"; +import { action } from "@ember/object"; +import { service } from "@ember/service"; +import { and } from "truth-helpers"; +import PluginOutlet from "discourse/components/plugin-outlet"; +import icon from "discourse-common/helpers/d-icon"; +import i18n from "discourse-common/helpers/i18n"; + +export default class TopicStatus extends Component { + @service currentUser; + + get canAct() { + return this.currentUser && !this.args.disableActions; + } + + @action + togglePinned(e) { + const { topic } = this.args; + topic.pinned ? topic.clearPin() : topic.rePin(); + e.preventDefault(); + } + + +} diff --git a/app/assets/javascripts/discourse/app/components/topic-status.hbs b/app/assets/javascripts/discourse/app/components/topic-status.hbs deleted file mode 100644 index 377e02f5188..00000000000 --- a/app/assets/javascripts/discourse/app/components/topic-status.hbs +++ /dev/null @@ -1,69 +0,0 @@ -{{~#if this.topicClosedArchived~}} - {{this.closedArchivedIcon}} -{{~/if~}} -{{~#if this.closedIcon~}} - {{this.closedIcon}} -{{~/if~}} -{{~#if this.archivedIcon~}} - {{this.archivedIcon}} -{{~/if~}} -{{~#if this.topicPrivateMessage~}} - {{this.privateMessageIcon}} -{{~/if~}} -{{~#if this.topicWarning~}} - {{this.warningIcon}} -{{~/if~}} -{{~#if this.topicPinned~}} - {{~#if this.canAct~}} - {{this.pinnedIcon}} - {{~else~}} - {{this.pinnedIcon}} - {{~/if~}} -{{~/if~}} -{{~#if this.topicUnpinned~}} - {{~#if this.canAct~}} - {{this.unpinnedIcon}} - {{~else~}} - {{this.unpinnedIcon}} - {{~/if~}} -{{~/if~}} -{{~#if this.topicInvisible~}} - {{this.invisibleIcon}} -{{~/if~}} - \ No newline at end of file diff --git a/app/assets/javascripts/discourse/app/components/topic-status.js b/app/assets/javascripts/discourse/app/components/topic-status.js deleted file mode 100644 index 74438ed5e5f..00000000000 --- a/app/assets/javascripts/discourse/app/components/topic-status.js +++ /dev/null @@ -1,104 +0,0 @@ -import Component from "@ember/component"; -import { htmlSafe } from "@ember/template"; -import $ from "jquery"; -import { iconHTML } from "discourse-common/lib/icon-library"; -import discourseComputed from "discourse-common/utils/decorators"; -import I18n from "discourse-i18n"; - -export default Component.extend({ - disableActions: false, - - classNames: ["topic-statuses"], - - click(e) { - // only pin unpin for now - if (this.canAct && $(e.target).hasClass("d-icon-thumbtack")) { - const topic = this.topic; - topic.get("pinned") ? topic.clearPin() : topic.rePin(); - return false; - } - }, - - @discourseComputed("disableActions") - canAct(disableActions) { - return this.currentUser && !disableActions; - }, - - @discourseComputed("topic.closed", "topic.archived") - topicClosedArchived(closed, archived) { - if (closed && archived) { - this._set("closedArchived", "lock", "locked_and_archived"); - this._reset("closed"); - this._reset("archived"); - return true; - } else { - this._reset("closedArchived"); - closed ? this._set("closed", "lock", "locked") : this._reset("closed"); - archived - ? this._set("archived", "lock", "archived") - : this._reset("archived"); - return false; - } - }, - - @discourseComputed("topic.is_warning") - topicWarning(warning) { - return warning - ? this._set("warning", "envelope", "warning") - : this._reset("warning"); - }, - - @discourseComputed( - "showPrivateMessageIcon", - "topic.isPrivateMessage", - "topic.is_warning" - ) - topicPrivateMessage(showPrivateMessageIcon, privateMessage, warning) { - return showPrivateMessageIcon && privateMessage && !warning - ? this._set("privateMessage", "envelope", "personal_message") - : this._reset("privateMessage"); - }, - - @discourseComputed("topic.pinned") - topicPinned(pinned) { - return pinned - ? this._set("pinned", "thumbtack", "pinned") - : this._reset("pinned"); - }, - - @discourseComputed("topic.unpinned") - topicUnpinned(unpinned) { - return unpinned - ? this._set("unpinned", "thumbtack", "unpinned", { class: "unpinned" }) - : this._reset("unpinned"); - }, - - @discourseComputed("topic.invisible") - topicInvisible(invisible) { - return invisible - ? this._set("invisible", "far-eye-slash", "unlisted") - : this._reset("invisible"); - }, - - _set(name, icon, key, iconArgs) { - this.set(`${name}Icon`, htmlSafe(iconHTML(`${icon}`, iconArgs))); - - const translationParams = {}; - - if (name === "invisible") { - translationParams.unlistedReason = this.topic.visibilityReasonTranslated; - } - - this.set( - `${name}Title`, - I18n.t(`topic_statuses.${key}.help`, translationParams) - ); - return true; - }, - - _reset(name) { - this.set(`${name}Icon`, null); - this.set(`${name}Title`, null); - return false; - }, -});