Sort by Solved/Unsolved Questions in Category

I wanted to know if there was a way to enable a sort feature for forums that have the solved plugin enabled to sort by Unsolved/Solved questions? The same way that we can sort on a Category by “Latest”, “New”, “Top”, “Unread” by clicking the link at the top.

I understand that this was sort of asked before, but I’m not sure exactly how to add a new sort “option” that has a link to reorganize the topics by those query params.

2 Likes

You can do something like that under Theme > Common (or Desktop, or Mobile, it’s your choise) > Body

<script>
  Discourse.ExternalNavItem = Discourse.NavItem.extend({
    href : function() {
      return this.get('href');
    }.property('href')
  });

  I18n.translations.en.js.filters.solved = { title: "Solved", help: "topics with solution" };
  I18n.translations.en.js.filters.unsolved = { title: "Unsolved", help: "topics without solution" };
  
  Discourse.NavItem.reopenClass({
    buildList : function(category, args) {
      var list = this._super(category, args);

      if(!category) {
        list.push(Discourse.ExternalNavItem.create({href: 'http://your-domain-url/?solved=yes', name: 'solved'}));
        list.push(Discourse.ExternalNavItem.create({href: 'http://your-domain-url/?solved=no', name: 'unsolved'}));
        
        
      }
      return list;
    }
  });
</script>

In this way you add the buttons Solved and Unsolved on your menu.
You need only to change the URLs with your domain (and customize with a particular category if you want, eg http://your-domain-url/c/support?solved=yes)

5 Likes

This will show the solved/unsolved buttons on the main pages, not the category pages.

If you want to add to category pages there’s an example here :slight_smile:

2 Likes

I had the same question but didn’t quite understand how to make it happen. Where do I add this script?
Would it possible to have a configuration button or setting checkbox to enable sorting by solved?

The Latest button remains hightlighted. Is there a way to highlight the Unsolved button when this link is entered?

2 Likes

It would really nice to have a button to sort or show only solved/unsolved posts. I know @david suggested a workaround to add custom HTML but if the plugin did that it would be awesome.

1 Like

Agreed.

I had a very brief look at adding it in the form of a theme component, but I think it will need some changes in the plugin itself first.
I think we need to a Boolean to the category serialiser, as currently there’s no way to know whether a category has “discourse-solved” enabled, its only shipped to the client on a “per-topic” basis.

Definitely achievable though :slight_smile:

3 Likes

Just checking in on this

This is still an issue - does anyone have any idea how to highlight the Unsolved button?

I don’t think there is a trivial way to do this yet… Maybe somebody can write a plugin or theme component…

@vinothkannans this is just so close to your other theme component, maybe also do one for this … “adds a [all/solved/unsolved] combo to categories with solved enabled?”

In fact, I would just add this to the plugin and have it be a default off site setting.

2 Likes

This does the trick of highlighting the Unsolved 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] === "?solved=no") {
        return contentFilterMode === "Unanswered";
      } else {
        return this._super(contentFilterMode, this.get('filterMode'));
      }
    }),
  });
4 Likes

It’s done. Added in the plugin itself (disabled by default).

https://github.com/discourse/discourse-solved/commit/5ddd644e000aaf9e50269a325a79bcac6974cee0

9 Likes

Awesome can you document this on the plugin page on meta and close this off.

4 Likes