This repository has been archived on 2023-03-18. You can view files and clone it, but cannot push or open issues or pull requests.
osr-discourse-src/app/assets/javascripts/discourse/app/widgets/topic-status.js
Osama Sayegh 61bb0df3f6
FEATURE: Allow topic pin toggle when header is docked (#15438)
Meta topic: https://meta.discourse.org/t/cant-pin-unpin-topic-from-the-title/213444?u=osama.

I know there is an inconsistency between the category of the linked topic (#bug) and the title prefix of this PR, but I really couldn't find anything in the code base that suggested this ever worked before, so I'm categorizing this PR as a feature.
2022-01-03 15:21:06 +03:00

41 lines
1.2 KiB
JavaScript

import I18n from "I18n";
import TopicStatusIcons from "discourse/helpers/topic-status-icons";
import { createWidget } from "discourse/widgets/widget";
import { escapeExpression } from "discourse/lib/utilities";
import { h } from "virtual-dom";
import { iconNode } from "discourse-common/lib/icon-library";
export default createWidget("topic-status", {
tagName: "span.topic-statuses",
html(attrs) {
const topic = attrs.topic;
const canAct = this.currentUser && !attrs.disableActions;
const result = [];
TopicStatusIcons.render(topic, function (name, key) {
const iconArgs = key === "unpinned" ? { class: "unpinned" } : null;
const icon = iconNode(name, iconArgs);
const attributes = {
title: escapeExpression(I18n.t(`topic_statuses.${key}.help`)),
};
let klass = "topic-status";
if (key === "unpinned" || key === "pinned") {
klass += `.pin-toggle-button.${key}`;
}
result.push(h(`${canAct ? "a" : "span"}.${klass}`, attributes, icon));
});
return result;
},
click(e) {
const parent = e.target.closest(".topic-statuses");
if (parent?.querySelector(".pin-toggle-button")?.contains(e.target)) {
this.attrs.topic.togglePinnedForUser();
}
},
});