Add like_count column to topic list


(Anthony Hopkins) #1

I need to display like_count to topic list.

I know I can add TopicViewSerializer.attributes_from_topic(:like_count) to my plugin and use outlet “topic-list-tags”

But perhaps there is a better way.
Any idea how to turn on this line?

It would be perfect if there is an option to “Like topic” directly from topic list.

(Erlend Sogge Heggen) #2

That’s not very feasible yet. Might change in the future. Explained here:

(Anthony Hopkins) #3

Thank you,

After many many tries I prepared working extension of ‘discourse/views/topic-list-item’ and click(e) event:

if (target.hasClass('like-count') || target.parents('.like-count').length > 0) {
  const topic = this.get('topic');
  Discourse.ajax(`/posts/by_number/${}/1`).then(result => {
    const post = Post.create(result);
    if(post.user_id == Discourse.User.current().id){
      return false;
    post.get('likeAction').togglePromise(post).then(resultLike => {
      if(resultLike.acted) {
        topic.like_count = topic.like_count+1;
        topic.like_count = topic.like_count-1;
  return false;

+ CSS + view extension.

I know it’s not perfect solution but Base works very well.