docbrown/app/views/articles/_full_comment_area.html.erb
Suzanne Aitchison 75b6c8ed96
Use a single listener for all follow buttons on a page (#14246)
* create new pack, handle user follow buttons, use pack on article page, remove initializeUserFollowButts

* init all follow button types, add pack to tag index and podcast episode pages

* add pack to all relevant pages, listen for newly inserted follow buttons

* change to searchParams to remove follow button initializer calls

* fix bug with tag page, add pack to notifications page

* fix issue with follow back inner text

* update cypress specs

* run the followbuttons code on sponsors page

* remove extra foreach

* add test for follow from article sidebar

* add test for follow and unfollow tag

* add test for the tag index page

* add spec for organisation profile follow

* add tests for follow buttons in search results

* add tests for notification follows

* commit missed file - woops

* show login modal if user is logged out when they click

* add cypress tests for logged out state

* change tag button initialization

* remove data-button-initialized

* init follow buttons from base pack

* handle the case where multiple follow buttons exist on a page for the same user

* account for instantclick and userdata not being defined, lower coverage for jest

* use getInstantClick

* fix issue with set initialisation

* only listen for mutations in areas we know follow buttons may be added dynamically

* small refactors
2021-07-27 10:45:50 +01:00

41 lines
1.9 KiB
Text

<% cache("whole-comment-area-#{@article.id}-#{@article.last_comment_at}-#{@article.show_comments}-#{@discussion_lock&.updated_at}", expires_in: 2.hours) do %>
<section id="comments" data-follow-button-container="true" data-updated-at="<%= Time.current %>" class="text-padding mb-4 border-t-1 border-0 border-solid border-base-10">
<% if @article.show_comments %>
<header class="relative flex justify-between items-center mb-6">
<h2 class="crayons-subtitle-1">Discussion <span class="js-comments-count" data-comments-count="<%= @article.comments_count %>">(<%= @article.comments_count %>)</span></h2>
<div id="comment-subscription" class="print-hidden">
<div role="presentation" class="crayons-btn-group">
<span class="crayons-btn crayons-btn--outlined">Subscribe</span>
</div>
</div>
</header>
<div
id="comments-container"
data-testid="comments-container"
data-commentable-id="<%= @article.id %>"
data-commentable-type="Article"
data-has-recent-comment-activity="<%= @article.has_recent_comment_activity? %>">
<% if @discussion_lock %>
<%= render "/comments/discussion_lock_reason" %>
<% else %>
<%= render "/comments/form", commentable: @article, commentable_type: "Article" %>
<% end %>
<div class="comments" id="comment-trees-container">
<% if @article.comments_count > 0 %>
<% Comment.tree_for(@article, @comments_to_show_count).each do |comment, sub_comments| %>
<% cache ["comment_root_cached_tree", comment] do %>
<%= tree_for(comment, sub_comments, @article) %>
<% end %>
<% end %>
<% end %>
</div>
</div>
<%= render "articles/comments_actions" %>
<% end %>
</section>
<% end %>
<% return if @warm_only %>