mirror of
https://github.com/discourse/discourse.git
synced 2024-12-09 17:13:44 +08:00
c34f8b65cb
As of #23867 this is now a real package, so updating the imports to use the real package name, rather than relying on the alias. The name change in the package name is because `I18n` is not a valid name as NPM packages must be all lowercase. This commit also introduces an eslint rule to prevent importing from the old I18n path. For themes/plugins, the old 'i18n' name remains functional.
65 lines
1.7 KiB
JavaScript
65 lines
1.7 KiB
JavaScript
import { action, computed } from "@ember/object";
|
|
import { htmlSafe } from "@ember/template";
|
|
import I18n from "discourse-i18n";
|
|
import DropdownSelectBoxComponent from "select-kit/components/dropdown-select-box";
|
|
|
|
const UNPINNED = "unpinned";
|
|
const PINNED = "pinned";
|
|
|
|
export default DropdownSelectBoxComponent.extend({
|
|
pluginApiIdentifiers: ["pinned-options"],
|
|
classNames: ["pinned-options"],
|
|
|
|
selectKitOptions: {
|
|
showCaret: true,
|
|
},
|
|
|
|
modifySelection(content) {
|
|
const pinnedGlobally = this.get("topic.pinned_globally");
|
|
const pinned = this.value;
|
|
const globally = pinnedGlobally ? "_globally" : "";
|
|
const state = pinned ? `pinned${globally}` : UNPINNED;
|
|
const title = I18n.t(`topic_statuses.${state}.title`);
|
|
|
|
content.label = htmlSafe(`<span>${title}</span>`);
|
|
content.title = title;
|
|
content.name = state;
|
|
content.icon = `thumbtack${state === UNPINNED ? " unpinned" : ""}`;
|
|
return content;
|
|
},
|
|
|
|
content: computed(function () {
|
|
const globally = this.topic.pinned_globally ? "_globally" : "";
|
|
|
|
return [
|
|
{
|
|
id: PINNED,
|
|
name: I18n.t(`topic_statuses.pinned${globally}.title`),
|
|
description: this.site.mobileView
|
|
? null
|
|
: I18n.t(`topic_statuses.pinned${globally}.help`),
|
|
icon: "thumbtack",
|
|
},
|
|
{
|
|
id: UNPINNED,
|
|
name: I18n.t("topic_statuses.unpinned.title"),
|
|
icon: "thumbtack unpinned",
|
|
description: this.site.mobileView
|
|
? null
|
|
: I18n.t("topic_statuses.unpinned.help"),
|
|
},
|
|
];
|
|
}),
|
|
|
|
@action
|
|
onChange(value) {
|
|
const topic = this.topic;
|
|
|
|
if (value === UNPINNED) {
|
|
return topic.clearPin();
|
|
} else {
|
|
return topic.rePin();
|
|
}
|
|
},
|
|
});
|