Add like_count column to topic list

AI-generated summary

A discussion is underway about adding a like_count column to the topic list. Anthony_Hopkins 1 requires this feature for their plugin and has found a possible solution by adding TopicViewSerializer.attributes_from_topic(:like_count) and using the “topic-list-tags” outlet. However, they are seeking a more straightforward method to enable the like_count feature directly in the topic list.

erlend_sh 2 responds that adding a “Like topic” option directly to the topic list is not feasible at present, citing a related discussion on meta discourse.

Anthony_Hopkins 3 shares their extension of the discourse/views/topic-list-item and click event, which allows users to like a topic directly from the topic list. Although it’s not a perfect solution, the base functionality works well.

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.

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

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.