Add like_count column to topic list

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?
https://github.com/discourse/discourse/blob/master/app/assets/javascripts/discourse/templates/list/topic-list-item.raw.hbs#L25

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

2 Likes

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

1 Like

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/${topic.id}/1`).then(result => {
    const post = Post.create(result);
    if(post.user_id == Discourse.User.current().id){
      bootbox.alert(I18n.t('cant_thumb_up'))
      return false;
    }
    post.get('likeAction').togglePromise(post).then(resultLike => {
      if(resultLike.acted) {
        target.closest('.like-count').toggleClass('liked');
        topic.like_count = topic.like_count+1;
        target.closest('.like-count').find('span').text(topic.like_count);
      }else{
        target.closest('.like-count').removeClass('liked');
        topic.like_count = topic.like_count-1;
        target.closest('.like-count').find('span').text(topic.like_count);
      }
    })
  });
  return false;
}

+ CSS + view extension.

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

3 Likes