2022-04-05 13:34:13 -04:00
|
|
|
import Component from "@ember/component";
|
|
|
|
import discourseComputed from "discourse-common/utils/decorators";
|
2022-04-05 14:23:15 -04:00
|
|
|
|
|
|
|
const enabledCategories = settings.enabled_categories
|
|
|
|
.split("|")
|
|
|
|
.map((id) => parseInt(id, 10))
|
|
|
|
.filter((id) => id);
|
2022-04-05 13:34:13 -04:00
|
|
|
|
|
|
|
export default Component.extend({
|
|
|
|
tagName: "",
|
|
|
|
hidden: true,
|
|
|
|
|
|
|
|
didInsertElement() {
|
|
|
|
this._super(...arguments);
|
2022-04-05 14:23:15 -04:00
|
|
|
this.recalculate();
|
|
|
|
},
|
|
|
|
|
|
|
|
didUpdateAttrs() {
|
|
|
|
this._super(...arguments);
|
|
|
|
this.recalculate();
|
2022-04-05 13:34:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
willDestroyElement() {
|
2022-04-05 14:23:15 -04:00
|
|
|
document.body.classList.remove("topic-in-gated-category");
|
2022-04-05 13:34:13 -04:00
|
|
|
},
|
|
|
|
|
2022-04-05 14:23:15 -04:00
|
|
|
recalculate() {
|
|
|
|
// do nothing if:
|
|
|
|
// a) topic does not have a category
|
|
|
|
// b) component setting is empty
|
|
|
|
// c) user is logged in
|
|
|
|
if (
|
|
|
|
!this.categoryId ||
|
|
|
|
enabledCategories.length === 0 ||
|
|
|
|
this.currentUser
|
|
|
|
) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enabledCategories.includes(this.categoryId)) {
|
|
|
|
document.body.classList.add("topic-in-gated-category");
|
|
|
|
this.set("hidden", false);
|
|
|
|
}
|
2022-04-05 13:34:13 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
@discourseComputed("hidden")
|
|
|
|
shouldShow(hidden) {
|
|
|
|
return !hidden;
|
|
|
|
},
|
|
|
|
});
|