Skip to content

Add avatars for reactions participants - #145

Closed
paulmolluzzo wants to merge 11 commits into
masterfrom
reactions-participants-new
Closed

paulmolluzzo wants to merge 11 commits into
masterfrom
reactions-participants-new

Conversation

@paulmolluzzo

Copy link
Copy Markdown
Contributor

Hat tip to @hkdobrev for getting this started and finding the way to get GH user avatars.

This extends the work @hkdobrev did on a new branch that is also up to date with master. Basically, it takes the avatars of people who add a reaction to a comment and appends their avatar. I am only appending the first 3 (or less) avatars because it quickly gets crazy, and then just add +${remainder} at the end.

Suggestions on the design are welcome. I'm thinking we can even get rid of the original number, but not sure.

Example:
reaction-avatars

@SpaceK33z

Copy link
Copy Markdown
Contributor

Wow, nice work!

Comment thread extension/content.js Outdated
const $reactionButtons = $reactionsContainer.find('.comment-reactions-options .reaction-summary-item[aria-label]');

$reactionButtons.each((index, element) => {
const participants = [];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Instead of the empty array here and the map below, how about just setting const participants to the return val from .split?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yup, good idea. Will do.

@DrewML

DrewML commented Apr 3, 2016

Copy link
Copy Markdown
Contributor

Nice work!

There is one small issue I spotted (that I don't think should preclude the PR, but we should address later). When you "react" to an issue, the user icon doesn't show until a page refresh. At that point, you obviously know which face should be there (your own!), but fixing it would make the UI feel a small bit more consistent.

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

This closes #95, BTW.

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

When you "react" to an issue, the user icon doesn't show until a page refresh.

Can fix. Thanks @DrewML

@paulmolluzzo
paulmolluzzo force-pushed the reactions-participants-new branch 2 times, most recently from 453e8ee to 1df71de Compare April 4, 2016 01:15
@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

OK, this is updated as follows:

  1. I fixed the participants array as suggested by @DrewML to make it easier to read.
  2. I changed the allParticipants variable name to participantsCount because it's more obvious what I'm doing with it.
  3. I added a check to make sure the div.participants-container that I use to put avatars in didn't exist. (This is to set up the suggestion to handle the "live" update.)
  4. I rebased the whole PR (with one exception). @hkdobrev's original work is still on https://github.com/sindresorhus/refined-github/tree/reactions-participants if we need it anyway.

About the suggestion in #145 (comment): I tried to do this, but the only "working" solution I have is to set an event listener with a window.setTimeout that does addReactionParticipants after 1 second. This is really not ideal, IMO, and kind of hacky. I tried to do this with a mutation observer, but that got super out of control and my browser kept crashing. If anyone has a suggestion please let me know. I didn't rebase that commit because it's still iffy to me.

@leocaseiro

Copy link
Copy Markdown
Contributor

Loved it!

How about adding border-radius: 3px;?

@leocaseiro

Copy link
Copy Markdown
Contributor

I agree you should remove the original number same way facebook does...

Comment thread extension/content.js Outdated
}
});

function addReactionParticipants() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Maybe move this to a separate file?

@sindresorhus

Copy link
Copy Markdown
Member

How about adding border-radius: 3px;?

👍

@sindresorhus

Copy link
Copy Markdown
Member

I don't think it should show your own avatar. That's pretty moot and you can already see you've voted.

@sindresorhus

Copy link
Copy Markdown
Member

I agree you should remove the original number same way facebook does...

👍

@sindresorhus

Copy link
Copy Markdown
Member

Seems to break the UI when there are a lot of different reactions: react/react#6322

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

I don't think it should show your own avatar. That's pretty moot and you can already see you've voted.

What if you're the only vote? It's going to look like this, which is weird:

👍 +1

Seems to break the UI when there are a lot of different reactions: react/react#6322

I can't see what's broken, can you screenshot?

@sindresorhus

Copy link
Copy Markdown
Member

What if you're the only vote? It's going to look like this, which is weird:

Drop the + in that case.

I can't see what's broken, can you screenshot?

screen shot 2016-04-04 at 20 41 48

Notice the white overflow below the reactions.

@hkdobrev

hkdobrev commented Apr 4, 2016

Copy link
Copy Markdown
Contributor

I'd recommend to exclude your own avatar from the list. You already have a different background colour if you have reacted with a certain emoji. No need to listen when you click and update it. Just never include your own avatar in the list.

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

I pushed changes and didn't squash (we can do that later).

I did everything suggested, but can't replicate that but you guys are seeing with the white space. I might have inadvertently fixed it when I removed the original count? Or maybe it was that unclosed CSS bracket?

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

Notice the white overflow below the reactions.

@sindresorhus I can't replicate. Can you try to figure what's happening? Please make sure you're up to date with what I pushed. It might be that the two reaction counts were doing it.

@sindresorhus

Copy link
Copy Markdown
Member

@paulmolluzzo Yes, I was using an older version of your PR. But even with latest, if you have enough reactions it will break. Might be an edge-case though. I tried adding two more reactions to react/react#6322 and this is what I got (using the latest version of this PR):

screen shot 2016-04-04 at 21 26 57

Can you fix the merge conflict and add this feature to the readme?

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

@sindresorhus I replicated it. I tightened up the padding on those buttons to compensate, but this will probably break if the post is super popular. An edge case for sure.

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

@sindresorhus BTW, moving this to a separate file broke the click event listening. I can't use the setTimeout from the new file. 😞

LMK if you have an idea for a solution or just want to take out the event binding or thing shoving this back into the main content.js is cool.

@hkdobrev

hkdobrev commented Apr 4, 2016

Copy link
Copy Markdown
Contributor

@paulmolluzzo I've suggested not listening to click and not showing your own reactions ever.

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

I've suggested not listening to click and not showing your own reactions ever.

@hkdobrev if everyone else agrees taking it out is super easy. I'm already not showing your own avatar, but your reaction is part of the total count.

e: "everyone else" meaning "anyone really". I kind of like it, but it's hacky right now.

@paulmolluzzo
paulmolluzzo force-pushed the reactions-participants-new branch 2 times, most recently from a14b40c to a0f5ca6 Compare April 5, 2016 00:48
@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

OK, I am pretty confident in the current version, and this time I did rebase everything to get it ready to merge. I'm still open to feedback on everything, so please let me know if anyone finds more bugs.

@hkdobrev, when you don't have the event listener for click on the buttons all the avatars just disappear and it looks like a bug, so I do think it should stay. However, I'm not showing the current User's avatar ever and it looks good. If you want to see what happens without the click, pull down the PR and comment out this line: a0f5ca6#diff-8f297dee0ce8264d927a877e48fec8acR12

@sindresorhus This is still in a separate file, and I should have fixed the UI issue correctly. The caveat to that is with enough reactions on enough different reactions it'll eventually break I think but that's probably a super edge case.

// @DrewML

@DrewML

DrewML commented Apr 5, 2016

Copy link
Copy Markdown
Contributor

This is awesome! Great work @paulmolluzzo!

One issue I'm seeing locally:

When "unreacting" to a reaction that has >= 1 other users that chose the same reaction, clicking on the reaction icon itself (rather than the outer blue area) throwns an exceptions, and doesn't unreact.

addreactionparticipants.js:12 Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: "script-src assets-cdn.github.com".

element.addEventListener @ addreactionparticipants.js:12

I'm getting a similar exception (using the [https://github.com/react/react/issues/6322](facebook issue thread) as a test-case) when I try to react using a reaction others have used, but it appears to be a bit sporadic right now.

Comment thread extension/content.css Outdated
height: 200px !important;
}

/* styles for reaction avatars */

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Specify that it's for our implementation:

styles for our reactions avatar feature

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

@sindresorhus fixed all the issues you pointed out and got this up to date with master.

document.addEventListener('click', event => {
addReactionParticipants.reapply(event, username);
});
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could rename username to currentUser for consistency and even put the reapply function body in addListener itself as reapplying only makes sense at the moment in the context of an event listener.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Changed the username param.

I'm not going to move the reapply function because leaving it here allows us to use it separately in another event listener or whatever.

@hkdobrev

hkdobrev commented Apr 6, 2016

Copy link
Copy Markdown
Contributor

I've been using the updated version and I really love it! ❤️

Comment thread extension/content.js
addPatchDiffLinks();
addReactionParticipants.add(username);
addReactionParticipants.addListener(username);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You could combine these in a single if (pageDetect.isPR() || pageDetect.isIssue() || pageDetect.isCommit()). I think it's more consistent, but it would also help with the fact isCommit() would return true for PR commits which match isPR() as well. So in some cases you would match both ifs and execute this twice. With a single if with 3 or expressions, you would execute it only once.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Pushed.

@hkdobrev

hkdobrev commented Apr 6, 2016 •

Copy link
Copy Markdown
Contributor

LGTM 💫 🎉 🎊

Comment thread readme.md Outdated
- [Adds links to patch and diff for each commit](https://cloud.githubusercontent.com/assets/737065/13605562/22faa79e-e516-11e5-80db-2da6aa7965ac.png)
- [Differentiates merge commits from regular commits](https://cloud.githubusercontent.com/assets/170270/14101222/2fe2c24a-f5bd-11e5-8b1f-4e589917d4c4.png)
- [Hides :+1: :-1: comments and shows their count in the sidebar](https://cloud.githubusercontent.com/assets/170270/13241396/0b708ae8-da1d-11e5-8c01-94eae501034c.png)
- [Adds user avatars to Reactions](https://cloud.githubusercontent.com/assets/737065/14269443/c80ae418-fab2-11e5-93f7-d776f40a5b25.png)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could you update the screenshot contents?

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

Updated the README @hkdobrev

@sindresorhus
sindresorhus deleted the reactions-participants-new branch April 6, 2016 18:49
@sindresorhus

Copy link
Copy Markdown
Member

Yay! 🎉✨ This is super good @paulmolluzzo. Thanks for working so hard on it :)

687474703a2f2f7777772e7265616374696f6e676966732e636f6d2f77702d636f6e74656e742f67616c6c6572792f64616e63652d70617274792f74756d626c725f6d306f73727268714d6b31717a6376376e6f345f3235302e676966

@DrewML

DrewML commented Apr 6, 2016

Copy link
Copy Markdown
Contributor

@paulmolluzzo Awesome work (and of course thanks @hkdobrev for getting this one started)!
P2MB29d7V3rhu

@hkdobrev

hkdobrev commented Apr 6, 2016

Copy link
Copy Markdown
Contributor

@paulmolluzzo Thanks for your very hard work on this! I know a code review so big and all of the amends are hard, but you've plowed through it flawlessly! The feature is working really great!

@hkdobrev

hkdobrev commented Apr 6, 2016

Copy link
Copy Markdown
Contributor

@sindresorhus the squashed commit you've made to master is attributed to me though which is not really fair. scratch that, I see you've fixed it and force pushed.

@paulmolluzzo

Copy link
Copy Markdown
Contributor Author

Thanks everyone! Would like to see an event listener for the socket if @DrewML has an idea there.

Thanks @hkdobrev for getting the ball rolling and finding that secret avatar URL, this pretty much only works because of that.

@hkdobrev

hkdobrev commented Apr 7, 2016

Copy link
Copy Markdown
Contributor

@sindresorhus Do you think you could tag and land this in the web store?

@sindresorhus

Copy link
Copy Markdown
Member

@hkdobrev Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

6 participants