Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update comment responses count when adding replies #4003

Merged

Conversation

Senen
Copy link
Member

@Senen Senen commented May 8, 2020

References

This PR is an alternative solution of the problem described here #4002.

Objectives

Update the parent comment "responses count" when a new reply is added.

The solution is about replacing parent comment responses count (which is also the toggler to show/hide children comments) when a new reply is added.

Changes introduced at 7105f21 (the comments part) are needed to initialize automatically comments added or replaced through ajax calls.

Steps to reproduce

  1. Go to any debate (or any other commentable resource)
  2. Add a reply to a comment

At this point you can see your reply but parent comment responses count is not updated!

Visual Changes

Before
ResponsesCountUpdateError

After
ResponsesCountUpdateFix

@Senen Senen added the Bug label May 8, 2020
@Senen Senen self-assigned this May 8, 2020
@Senen Senen added this to Reviewing in Consul Democracy via automation May 8, 2020
@Senen Senen force-pushed the fix-comments-reply-alternate branch from 66369e0 to 096eb73 Compare May 9, 2020 07:42
@Senen Senen moved this from Reviewing to Doing in Consul Democracy May 9, 2020
@Senen Senen force-pushed the fix-comments-reply-alternate branch from 096eb73 to c24597c Compare May 12, 2020 16:49
@Senen Senen force-pushed the fix-comments-reply-alternate branch from c24597c to 66b2afb Compare May 12, 2020 18:35
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great 😄. I've just merged #4008, so we can probably rebase this one against latest master.

I've left a couple of comments 😄.

app/views/comments/create.js.erb Outdated Show resolved Hide resolved
spec/system/comments/budget_investments_spec.rb Outdated Show resolved Hide resolved
spec/system/comments/debates_spec.rb Outdated Show resolved Hide resolved
app/assets/javascripts/users.js Outdated Show resolved Hide resolved
@Senen Senen force-pushed the fix-comments-reply-alternate branch 2 times, most recently from 51567d9 to 6234553 Compare May 14, 2020 17:04
@javierm javierm marked this pull request as ready for review May 14, 2020 17:38
@Senen Senen force-pushed the fix-comments-reply-alternate branch from 6234553 to 343a1c5 Compare May 15, 2020 14:09
app/assets/stylesheets/layout.scss Outdated Show resolved Hide resolved
app/assets/stylesheets/layout.scss Outdated Show resolved Hide resolved
app/assets/stylesheets/layout.scss Outdated Show resolved Hide resolved
app/assets/stylesheets/layout.scss Outdated Show resolved Hide resolved

.responses-count {
.far {
@extend .fa-minus-square;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using placeholder selectors (e.g. %some-placeholder) with @extend

Copy link
Member

@javierm javierm May 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately font-awesome doesn't provide mixins nor placeholder selectors for these styles. We could write:

      .far::before {
        content: fa-content($fa-var-minus-square);
      }

But, to be honest, this feels like copying the body of a method instead of calling the method. I'd rather use @extend, even if we aren't following the rules 😌. On the other hand, having style warnings is annoying 😅. @Senen What you decide is fine with me 😉.

@Senen Senen force-pushed the fix-comments-reply-alternate branch from ef4915c to 8bf8726 Compare May 15, 2020 15:44
@javierm javierm moved this from Doing to Reviewing in Consul Democracy May 16, 2020
app/assets/javascripts/comments.js Outdated Show resolved Hide resolved
app/assets/stylesheets/layout.scss Outdated Show resolved Hide resolved
app/assets/javascripts/comments.js Outdated Show resolved Hide resolved

.responses-count {
.far {
@extend .fa-minus-square;
Copy link
Member

@javierm javierm May 17, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately font-awesome doesn't provide mixins nor placeholder selectors for these styles. We could write:

      .far::before {
        content: fa-content($fa-var-minus-square);
      }

But, to be honest, this feels like copying the body of a method instead of calling the method. I'd rather use @extend, even if we aren't following the rules 😌. On the other hand, having style warnings is annoying 😅. @Senen What you decide is fine with me 😉.

@javierm javierm moved this from Reviewing to Doing in Consul Democracy May 18, 2020
@Senen Senen force-pushed the fix-comments-reply-alternate branch from 8bf8726 to 9951ec0 Compare May 25, 2020 09:47
margin-top: $line-height / 2;
&.collapsed {
.far {
@extend .fa-plus-square;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using placeholder selectors (e.g. %some-placeholder) with @extend

@Senen Senen force-pushed the fix-comments-reply-alternate branch from 9951ec0 to 4bc3d82 Compare May 25, 2020 10:13
Senen and others added 4 commits May 26, 2020 13:20
Extract the needed portion of code to a new partial to be able to update
only the elements needed when a new comment is added keeping UI properly
updated.
When a user replies to a comment whose responses was hidden at the
moment of reply form submission and although the reply were correctly
added to the DOM it was hidden because was added to a collapsed list.

This solution is about showing all responses of parent comment after adding
the new comment to the DOM so the user can see new reply into the screen.
(This is not applicable to root comments which cannot be collapsed)
Co-Authored-By: Javi Martín <javim@elretirao.net>
@Senen Senen force-pushed the fix-comments-reply-alternate branch from 4bc3d82 to 31c0b43 Compare May 26, 2020 11:20
Copy link
Member

@javierm javierm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome! 🎉 Amazing how tricky this issue was. Thanks a lot! 😄

Consul Democracy automation moved this from Doing to Testing May 26, 2020
@javierm
Copy link
Member

javierm commented May 26, 2020

Travis failure is not related to this pull request and will be solved by #4023.

@javierm javierm merged commit a3ed4e3 into consuldemocracy:master May 26, 2020
Consul Democracy automation moved this from Testing to Release 1.2.0 May 26, 2020
@javierm javierm self-assigned this Jun 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants