Sort by likes in 2.5.0.beta6

Previously, we were using @sam’s suggestion to provide an option to sort topics in a category by likes, but as of 2.5.0.beta6 this appears to no longer be working.

TypeError: undefined is not an object (evaluating 'Discourse.SiteSettings.top_menu = 'categories|latest|top|new|unread'')

Is there a new method to enable this functionality?

1 Like

Hmm, I didn’t immediately run into the same error when trying it out. With that said, the code you linked to is quite old these days! I think this should cover most of the modern patterns and achieve the same (or better) result. Can you give it a try, of course with values that make sense for your community?

<script type="text/discourse-plugin" version="0.10.0">
  const I18n = require("I18n").default;
  I18n.translations.[I18n.locale].js.filters.topliked = { help: "Top Liked" };

  api.addNavigationBarItem({
    displayName: "Top Liked",
    name: "topliked",
    before: "top",
    href: "?order=op_likes&status=open",
    customFilter: category => {
      return category && category.name === "Testing"
    },
    forceActive: (category, args, router) => { 
        const queryParams = router.currentRoute.queryParams;
        return (
          queryParams &&
          Object.keys(queryParams).length === 2 &&
          queryParams["order"] === "op_likes" &&
          queryParams["status"] === "open"
        );
    }
  });
</script>
5 Likes

This works beautifully. Thanks!

3 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.