Reply reminder - Remind users to reply to new users topics with zero replies

Was able to get most of the way there looking at Custom top navigation links.

<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 = '?max_posts=1';
// Exclude certain categories from showing the needs reply menu item
let excludeList = ['pitches', 'weekly-recap', 'staff'];

api.addNavigationBarItem({
name: "needsreply",
displayName:"Needs Reply",
title: "Needs Reply",
href: "/latest" + search_query
});

// 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');
        console.log(window.location.search.split('&')[0], search_query.split('&')[0])
        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();
    }
});


</script>

The only part I haven’t been able to figure out is how to access the current category in this script.

In the original code, Discourse.NavItem allows you to access the current category. Based on this code, we dynamically alter the behavior of the link (hide it, or change the href to only look at posts in this category).

Can anyone recommend a solution to inject the current category into the script above so I can customize the behavior of the link depending on what category the user is viewing?

1 Like