Skip to content

Commit db2fdb6

Browse files
committed
show who reacted
1 parent 610add2 commit db2fdb6

File tree

5 files changed

+249
-219
lines changed

5 files changed

+249
-219
lines changed

src/Post.js

Lines changed: 56 additions & 128 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@ import MarkdownRenderer from './MarkdownRenderer';
1212
import formatDate from 'date-fns/format';
1313
import EmojiIcon from './emojiIcon';
1414
import AddIcon from './addIcon';
15-
import Tippy from '@tippy.js/react';
15+
import Tippy, {TippyGroup} from '@tippy.js/react';
1616
import 'tippy.js/themes/light-border.css';
1717
import {Link} from 'react-router-dom';
1818
import {postRootQuery} from './App';
1919
import GitHubLoginButton from './GitHubLoginButton';
2020
import {NotificationContext} from './Notifications';
2121
import {Box, Heading, Text} from 'grommet';
2222
import UserContext from './UserContext';
23+
import {lowerCase, sentenceCase} from 'change-case';
2324

2425
import type {Post_post} from './__generated__/Post_post.graphql';
2526

@@ -269,26 +270,61 @@ const Post = ({relay, post}: Props) => {
269270
)}
270271
</Box>
271272
) : null}
273+
272274
<Box
273275
pad="xsmall"
274276
direction="row"
275277
wrap={true}
276278
border={{size: 'xsmall', side: 'top', color: 'rgba(0,0,0,0.1)'}}>
277-
{usedReactions.map(g => (
278-
<Text
279-
key={g.content}
280-
style={{
281-
padding: '0 16px',
282-
borderRight: '1px solid rgba(0,0,0,0.12)',
283-
display: 'flex',
284-
alignItems: 'center',
285-
}}>
286-
{emojiForContent(g.content)}{' '}
287-
<Text size="small" style={{marginLeft: 8}}>
288-
{g.users.totalCount}
289-
</Text>
290-
</Text>
291-
))}
279+
<TippyGroup delay={500}>
280+
{usedReactions.map(g => {
281+
const total = g.users.totalCount;
282+
const reactors = g.users.nodes.map(x => x.login);
283+
if (total > 11) {
284+
reactors.push(`${total - 11} more`);
285+
}
286+
287+
const reactorsSentence = [
288+
...reactors.slice(0, reactors.length - 2),
289+
reactors.slice(-2).join(reactors.length > 2 ? ', and ' : ' and '),
290+
].join(', ');
291+
292+
return (
293+
<Tippy
294+
key={g.content}
295+
arrow={true}
296+
trigger="mouseenter focus click"
297+
placement="bottom"
298+
flipBehavior={['bottom', 'right']}
299+
theme="light-border"
300+
inertia={true}
301+
interactive={true}
302+
animateFill={false}
303+
interactiveBorder={10}
304+
duration={[75, 75]}
305+
content={
306+
<div>
307+
{reactorsSentence} reacted with{' '}
308+
{lowerCase(sentenceCase(g.content))} emoji
309+
</div>
310+
}>
311+
<span
312+
key={g.content}
313+
style={{
314+
padding: '0 16px',
315+
borderRight: '1px solid rgba(0,0,0,0.12)',
316+
display: 'flex',
317+
alignItems: 'center',
318+
}}>
319+
<Text>{emojiForContent(g.content)} </Text>
320+
<Text size="small" style={{marginLeft: 8}}>
321+
{g.users.totalCount}
322+
</Text>
323+
</span>
324+
</Tippy>
325+
);
326+
})}
327+
</TippyGroup>
292328
<Tippy
293329
onCreate={instance => (popoverInstance.current = instance)}
294330
arrow={true}
@@ -368,8 +404,11 @@ export default createFragmentContainer(Post, {
368404
reactionGroups {
369405
content
370406
viewerHasReacted
371-
users {
407+
users(first: 11) {
372408
totalCount
409+
nodes {
410+
login
411+
}
373412
}
374413
}
375414
comments {
@@ -378,114 +417,3 @@ export default createFragmentContainer(Post, {
378417
}
379418
`,
380419
});
381-
382-
const WORDS = [
383-
'people',
384-
'see',
385-
'one',
386-
'make',
387-
'day',
388-
'it’s',
389-
'man',
390-
'old',
391-
'out',
392-
'dog',
393-
'guy',
394-
'new',
395-
'video',
396-
'things',
397-
'life',
398-
'made',
399-
'year',
400-
'never',
401-
'facebook',
402-
'awesome',
403-
'girl',
404-
'look',
405-
'photos',
406-
'love',
407-
'know',
408-
'best',
409-
'way',
410-
'thing',
411-
'beautiful',
412-
'time',
413-
'little',
414-
'more',
415-
'first',
416-
'happened',
417-
'heart',
418-
'now',
419-
'you’ll',
420-
'being',
421-
'ways',
422-
'want',
423-
'think',
424-
'something',
425-
'years',
426-
'found',
427-
'better',
428-
'seen',
429-
'baby',
430-
'really',
431-
'world',
432-
'actually',
433-
'valentine’s',
434-
'down',
435-
'reasons',
436-
'watch',
437-
'need',
438-
'here',
439-
'good',
440-
'media',
441-
'makes',
442-
'boy',
443-
'mind',
444-
'right',
445-
'social',
446-
];
447-
448-
function blockWord(size: number): string {
449-
let res = '';
450-
for (let i = 0; i < size; i++) {
451-
res += '█';
452-
}
453-
return res;
454-
}
455-
456-
function randInt(x: number): number {
457-
return Math.floor(Math.random() * x);
458-
}
459-
460-
function randomWord() {
461-
// return WORDS[randInt(WORDS.length)];
462-
return blockWord(randInt(4) + 1);
463-
}
464-
465-
function capitalize(s: string): string {
466-
return s.charAt(0).toUpperCase() + s.slice(1);
467-
}
468-
469-
export class LoadingPost extends React.PureComponent<*, *> {
470-
render() {
471-
return (
472-
<PostBox>
473-
<Box pad="medium" style={{opacity: '0.6'}} className="shimmer">
474-
<Heading level={3} margin="none">
475-
██ ██ ██
476-
</Heading>
477-
<Text size="xsmall">█ █ ██</Text>
478-
<Text size="small">
479-
<MarkdownRenderer
480-
source={`█ ██ █ █ ██ ██ █ ██ ██ ██ ██ █ █ ██ █ ██ █ ██ █ █ █ █ ██ ██ ██ ██ █ █ ██ █ ██ ██ █ █ ██ █ █ █ ██ █ ██ █ ██ ██ ██ █ ██ ██ █ ██ ██ █ █ ██ █ █ ██ ██ ██ █ █ ██ █ █ █ █ █ █ ██ ██ █ ██ ██ █ ██ ██ ██ ██ █ ██ █ █ █ ██ █ █ ██ ██ ██ ██ █ █ ██ █ █ ██ █ ██ █ █ ██ ██ █ █ █ █ ██ █ ██ █ ██ █ █ █ ██ ██ █ █ █ █ ██ ██
481-
482-
██ ██ ██ █ █ █ █ █ ██ ██ ██ █ ██ ██ ██ ██ █ ██ █ █ █ █ ██ █ ██ █ █ █ █ █ █ █ ██ ██ █ █ █ █ █ █ ██ ██ █ █ ██ ██ ██ █ ██ ██ █ █ █ ██ █ █ █ ██ █ █ ██ ██ █ █ █ ██ ██ █ █ █ █ ██ ██ ██ ██ █ █ ██ ██ ██ █ █ █ █ █ █ ██ █ ██ █ █ ██ █ █ █ █ █ ██ █ ██ ██ ██ ██ █ ██ ██ ██ █ █ █ ██ █ ██ █ ██ █ ██ █ ██ ██ ██ █ █ ██ ██ █ ██ ██ ██ ██ █ ██ █ █ ██ ██ █ ██ ██ █ ██ █ █ ██ █ █ ██ █ █ █ ██ █ ██ █ ██ █ █ █ █ █ ██ █ █ ██ █ ██ ██ ██ █ █ █ ██ █ ██ ██ ██ █ ██ █ █ ██ ██ ██ █ █ █ █ ██ ██ █ ██ ██ █ ██ ██ ██ █ ██ █
483-
484-
██ █ █ █ ██ ██ ██ █ ██ ██ ██ ██ █ ██ ██ ██ ██ █ ██ ██ █ ██ █ ██ ██ ██ ██ ██ ██ ██ █ ██ ██ █ ██ ██ ██ ██ ██ █ █ ██ ██ █ █ ██ █ ██ █ ██ █ ██ █ █ ██ ██ █ ██ ██ █ ██ ██ █ ██ █ ██ ██ ██ █ █ █ ██ ██ ██ ██ ██ ██ █ █ ██ █ ██ █ ██ █ ██ █ ██ █ █ ██ ██ ██ ██ ██ ██ ██ █ █ █ █ ██ █ █ █ █ █ █ ██ █ █ ██ █ █ ██ █ ██ █ ██ ██ ██ █ █ █ █ █ ██ ██ █ █ ██ █ █ █ █ ██ ██ █ █`}
485-
/>
486-
</Text>
487-
</Box>
488-
</PostBox>
489-
);
490-
}
491-
}

src/__generated__/App_Post_Query.graphql.js

Lines changed: 49 additions & 23 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)