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

Likes Fix (button mashing and initial negative likes) #4852

Merged
merged 15 commits into from
Mar 16, 2019

Conversation

sashadev-sky
Copy link
Member

@sashadev-sky sashadev-sky commented Feb 18, 2019

Fixes #3524, #4589

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with rake test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • PR is descriptively titled 📑
  • screenshots/GIFs are attached 📎 in case of UI updation
  • ask @publiclab/reviewers for help, in a comment below

================

Please find notes and GIFs here:

https://github.com/sashadev-sky/PL-notes/blob/master/likes.md

===============

@sashadev-sky sashadev-sky changed the title Likes Fix Likes Fix (button mashing and initial negative likes) Feb 18, 2019
@plotsbot
Copy link
Collaborator

plotsbot commented Feb 18, 2019

1 Warning
⚠️ It looks like you merged from master in this pull request. Please rebase to get rid of the merge commits – you may want to rewind the master branch and rebase instead of merging in from master, which can cause problems when accepting new code!
1 Message
📖 @sashadev-sky Thank you for your pull request! I’m here to help with some tips and recommendations. Please take a look at the list provided and help us review and accept your contribution! And don’t be discouraged if you see errors – we’re here to help.

Generated by 🚫 Danger

@sashadev-sky
Copy link
Member Author

@jywarren From working with this code I have felt like the notification popups UI isn't compatible with the 'like' and 'unlike' functionalities. I was thinking maybe to just remove them all together as they might be replaced when a notifications API is fully integrated with the site. Please see my comments and GIFs in the link in my PR description and let me know your thoughts! Thank you

@avsingh999
Copy link
Member

@sashadev-sky can you please add Gif
thanks : )

@sashadev-sky
Copy link
Member Author

@avsingh999 the Gif is linked in the PR request description. It wouldn't let me drag it here because the file was too large

@avsingh999
Copy link
Member

@avsingh999 the Gif is linked in the PR request description. It wouldn't let me drag it here because the file was too large

Sorry I didn't see 😄

@namangupta01
Copy link
Member

Hi @sashadev-sky, the right approach for doing this according to me is update the likes when we get the response with the number of likes. And disable the button when the request is taking place of the previous like. What do you think?

@sashadev-sky
Copy link
Member Author

@namangupta01 I think disabling a button does not prevent event listeners from firing. So that is why I had to make sure to turn them off in between promises

@namangupta01
Copy link
Member

By disabling the button, I mean to stop progressing the event when request is going on using preventDefault or by using if else.

Gemfile Outdated Show resolved Hide resolved
Gemfile Outdated Show resolved Hide resolved
Gemfile Outdated Show resolved Hide resolved
}

// note useful for comments on notes but maybe useful for something else.
// if(window.location.href.includes("#like")) {
Copy link
Member

Choose a reason for hiding this comment

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

It would be better to remove unused code.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don’t think code should be deleted before you know the reason it was put there in the first place. As noted in its comment I am still investigating that and this PR is not labeled for review. If you have input on the function of it that would be useful. Thank you

Copy link
Member

Choose a reason for hiding this comment

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

You could look through the blame view for this file to see when it was added and when removed, and see if you can track it that way!

Copy link
Member Author

Choose a reason for hiding this comment

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

It actually doesn't do anything helpful I looked into it. But instead of removing it I will comment it out. I think I will open a new issue after this for implementing likes on comments (currently not working) and fix it up there. Is that okay with everyone? So the uncommented code will just be there for a bit.

spec/javascripts/plots2_spec.js Show resolved Hide resolved
app/assets/javascripts/like.js Show resolved Hide resolved
app/assets/javascripts/like.js Show resolved Hide resolved
@sashadev-sky
Copy link
Member Author

sashadev-sky commented Feb 22, 2019

@namangupta01 this pull request is marked as “in progress” I will make the gem updates when I’m ready for merge review 👍🏻

@namangupta01
Copy link
Member

No problem, let me know if you need some help! 👍

@sashadev-sky
Copy link
Member Author

sashadev-sky commented Feb 22, 2019

@namangupta01 I don't quite understand the change you are suggesting. I don't think preventdefault should have any effect on the button in this scenario as it is not a form submission

also if you could help me write front end tests that would be great!! It's my first time writing them I could use some help

@jywarren
Copy link
Member

Hi @sashadev-sky - by front end tests do you mean front-end javascript tests? We do some JavaScript tests here: https://github.com/publiclab/plots2/tree/master/spec/javascripts but they're not great because they are only run against static fixtures, which need to be kept up to date. There's a little about this here:

https://github.com/publiclab/plots2/blob/master/doc/TESTING.md#client-side-tests

I'm also interested in exploring system tests, in #3683, and i just opened a PR here: #4888 (though not sure if it will run).

That will actually run a full-stack version of the site in Chrome, and allows click interactions, so it really tests the whole system. I think this could be a good way forward for testing likes and we may want to move away from the teaspoon/mocha tests since they can't test on dynamic data, and require the static fixtures to be maintained. What do you think?

package.json Outdated Show resolved Hide resolved
Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

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

Small changes - likers.count - but all good otherwise! Good work here! This has long been a bit of an untidy part of our JS code. Thanks!

@sashadev-sky sashadev-sky force-pushed the likes-fix branch 5 times, most recently from f7b12d6 to c672c96 Compare March 6, 2019 10:21
@jywarren
Copy link
Member

jywarren commented Mar 12, 2019

Spinner idea: <i class="fa fa-spinner fa-spin"></i> - could indicate to user to stop clicking

you could also add disabled class too. jquery toggleClass()

@jywarren
Copy link
Member

Folks have asked about what debounce means and how this strategy works. @sashadev-sky here's a link to a great explanation: https://css-tricks.com/debouncing-throttling-explained-examples/ -- it can really help throttle client/server interactions and make things smoother. I recently implemented it in this PR with @aashna27 's help: #4904

Example of debounce: https://github.com/publiclab/plots2/pull/4904/files#diff-128f89a0762ba84f1ad9619753645287R15

@jywarren
Copy link
Member

https://css-tricks.com/the-difference-between-throttling-and-debouncing/

@jywarren
Copy link
Member

jywarren commented Mar 12, 2019

$('.myButton').click(debounce(function onClick(){
   // ... do things
}, 350);

350 is the # of milliseconds. Play around with 100-350 range

@jywarren
Copy link
Member

@jywarren
Copy link
Member

@sashadev-sky
Copy link
Member Author

@jywarren likes are debounced! Please review. Not much update to show in terms of UI so the gif in the description is basically the same still as what I saw when running it on the unstable branch. I also saw from the waterfall in Chrome dev tools that the debounce is taking pauses for the requests and not every click will lead to a request when mashing the button.

@jywarren
Copy link
Member

Awesome and well done here!!!

@jywarren jywarren merged commit 3cc86dd into publiclab:master Mar 16, 2019
icarito pushed a commit to icarito/plots2 that referenced this pull request Apr 9, 2019
* version updates

* squash commits

* leave note for bridge into next likes functionaliy fix

* squash commits

* leave note for bridge into next likes functionaliy fix

* disable noty notification for likes and comment likes

* fix comment template if statement

* updates

* check no debounce

* debounce likes

* debounce
SrinandanPai pushed a commit to SrinandanPai/plots2 that referenced this pull request May 5, 2019
* version updates

* squash commits

* leave note for bridge into next likes functionaliy fix

* squash commits

* leave note for bridge into next likes functionaliy fix

* disable noty notification for likes and comment likes

* fix comment template if statement

* updates

* check no debounce

* debounce likes

* debounce
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants