I have a theme component to not display muted tags and categories in search, but I disabled it and then re-enabled it to test something else, and now it’s not working, including console.log. I can’t get api.decoratePluginOutlet to do anything at all, even in a new clean theme component based off the example in plugin-api.js
A. is there a trick to getting decoratePluginOutlet to work, and B. is there a better way to just add a class to a search result list item? Right now I’m using decoratePluginOutlet to get the element and walk up and down the hierarchy to find and then add the category, but this feels messy. Full code below.
<script type="text/discourse-plugin" version="0.8">
const discourseComputed = require("discourse-common/utils/decorators").default;
let currentUser = api.getCurrentUser();
api.decoratePluginOutlet(
"full-page-search-category",
(elem, args) => {
console.log(currentUser)
let searchCategory = elem.parentElement.parentElement
let fpsTopic = searchCategory.parentElement.parentElement
let category_id = searchCategory.children[0].getAttribute('href').split("/").slice(-1);
let search_children = searchCategory.children
let searchArray = Array.from(search_children)
let tags = searchArray.filter(item => item.classList.contains("discourse-tags"))
if (tags[0]) {
let tagList = Array.from(tags[0].children).map(x => x.innerText)
for (let index = 0; index < tagList.length; ++index) {
fpsTopic.classList.add("tagged_" + tagList[index])
}
console.log()
}
fpsTopic.classList.add("category_" + category_id)
if (currentUser) {
const muted_categories = currentUser.muted_category_ids
const muted_tags = currentUser.muted_tags
if (muted_categories) {
if (muted_categories.includes(parseInt(category_id))) {
const children = fpsTopic.childNodes;
const newNode = document.createElement("a");
const textNode = document.createTextNode("This result is from a category you have muted.");
newNode.classList.add("block-notice")
newNode.appendChild(textNode);
newNode.onclick = function() { showComment(this); };
fpsTopic.insertBefore(newNode, fpsTopic.children[0]);
fpsTopic.classList.add("blocker-blocked");
newNode.classList.remove("blocker-blocked");
}
}
if (muted_tags && tags[0]) {
let tagList = Array.from(tags[0].children).map(x => x.innerText)
if (muted_tags.some(v => tagList.includes(v))) {
const children = fpsTopic.childNodes;
const newNode = document.createElement("a");
const textNode = document.createTextNode("This result is from a tag you have muted.");
newNode.classList.add("block-notice")
newNode.appendChild(textNode);
newNode.onclick = function() { showComment(this); };
fpsTopic.insertBefore(newNode, fpsTopic.children[0]);
fpsTopic.classList.add("blocker-blocked");
newNode.classList.remove("blocker-blocked");
}
}
}
}
);
function showComment(elem) {
const cooked = elem.parentNode;
elem.remove();
cooked.classList.remove("blocker-blocked");
}
</script>