Override class list

Currently working out of an initializer for my custom plugin - I want to be able to add an arbitrary class (locked-category) for each locked category, but can’t quite figure out how.

I’m aware that I can edit the template for topic-list-item, however the class is conditional, dependent on whether the topic is locked or not.

Here’s the code in question:
TopicStatus.reopen({ statuses(){ if (this.topic.is_locked_down) { // I'd like to add the class to topic's classList } ... })

If anyone has ideas, anything is appreciated!

1 Like

If

in your post refers to categories with limited read permissions then something like this will work if you add it to your initializer.

api.modifyClass("component:topic-list-item", {
  didInsertElement() {
    this._super(...arguments); // ensures core code runs first

    const privateCategory = this.topic.category.read_restricted;
    if (privateCategory) {
      // adds the class to topic list items that meet the conditional above 
      this.element.classList.add("locked-category");
    }
  }
});
3 Likes

Awesome, got it working, much appreciated!

2 Likes