We’ve been using this theme component for some time, and today it broke.
Here’s the component code (common, head_tag.html)
<!-- NEEDS REPLY -->
<script type="text/discourse-plugin" version="0.8.18">
if (I18n.translations.en) {
I18n.translations.en.js.filters.needsreply = {title: "Needs Reply", help: "Unanswered Topics"};
}
// CUSTOMIZE THESE VALUES
// Set the search query
let search_query = '?ascending=false&max_posts=1';
// Exclude certain categories from showing the needs reply menu item
let excludeList = ['pitches', 'weekly-recap', 'staff'];
// Add active class to Needs Reply button
api.modifyClass('component:navigation-item', {
active: Ember.computed("contentFilterMode", "filterMode", function () {
let contentFilterMode = this.get('content').get('filterMode');
if (window.location.search && window.location.search.split('&')[0] === search_query.split('&')[0]) {
return contentFilterMode === "needsreply";
} else {
return this._super(contentFilterMode, this.get('filterMode'));
}
}),
});
// Remove max_posts filter and tags filter
api.modifyClass('controller:discovery/topics', {
resetParams: function () {
this.setProperties({max_posts: null});
this.setProperties({tags: null});
this._super();
}
});
Discourse.ExternalNavItem = Discourse.NavItem.extend({
href: function () {
return this.get('href');
}.property("href")
});
Discourse.NavItem.reopenClass({
buildList: function (category, args) {
let list = this._super(category, args),
tag = args.tagId,
needsreplyHref;
if (!category) { // does not have a category
needsreplyHref = tag ? '/latest/' + search_query + '&tags=' + tag : '/latest/' + search_query; // if there's a tag build the href with the tag, else fall back to the latest view and the search query
}
else if (excludeList.indexOf(category.slug) != -1) { // the category is in the exclude list, do nothing
return list; // return the list without creating the custom nav item
}
else if (!category.parentCategory) { // is not a sub-category
needsreplyHref = tag ? '/c/' + category.slug + search_query + '&tags=' + tag : '/c/' + category.slug + search_query; // if there's a tag build the href with tags and the category, else fallback to the search query et al
} else { // is a sub-category
needsreplyHref = tag ? '/c/' + category.parentCategory.slug + '/' + category.slug + search_query + '&tags=' + tag :
'/c/' + category.parentCategory.slug + '/' + category.slug + search_query; // if there's a tag build the href with tags, sub-cateogry, and category, else fallback to search query et al
}
list.push(Discourse.ExternalNavItem.create({href: needsreplyHref, name: 'needsreply'}));
return list;
}
});
</script>
There’s an error in the JS console:
And digging into a bit more I found this post talking about Discourse.NavItem being deprecated:
Any suggestions for rewriting this without the deprecated NavItem class?