From c9292544aabe73a35eaadff843a89e469773beab Mon Sep 17 00:00:00 2001 From: Ken Powers Date: Thu, 6 Feb 2020 14:57:46 -0500 Subject: [PATCH] Show clicked-on reaction in ReactionViewer --- ts/components/conversation/Message.tsx | 19 ++++++++++---- ts/components/conversation/ReactionViewer.md | 25 +++++++++++++++++++ ts/components/conversation/ReactionViewer.tsx | 7 +++--- 3 files changed, 43 insertions(+), 8 deletions(-) diff --git a/ts/components/conversation/Message.tsx b/ts/components/conversation/Message.tsx index 5697ce5559..24768c0817 100644 --- a/ts/components/conversation/Message.tsx +++ b/ts/components/conversation/Message.tsx @@ -161,6 +161,7 @@ interface State { isSelected: boolean; prevSelectedCounter: number; + pickedReaction?: string; reactionViewerRoot: HTMLDivElement | null; reactionPickerRoot: HTMLDivElement | null; @@ -1417,7 +1418,10 @@ export class Message extends React.PureComponent { ); } - public toggleReactionViewer = (onlyRemove = false) => { + public toggleReactionViewer = ( + onlyRemove = false, + pickedReaction?: string + ) => { this.setState(({ reactionViewerRoot }) => { if (reactionViewerRoot) { document.body.removeChild(reactionViewerRoot); @@ -1427,7 +1431,7 @@ export class Message extends React.PureComponent { true ); - return { reactionViewerRoot: null }; + return { reactionViewerRoot: null, pickedReaction }; } if (!onlyRemove) { @@ -1441,10 +1445,11 @@ export class Message extends React.PureComponent { return { reactionViewerRoot: root, + pickedReaction, }; } - return { reactionViewerRoot: null }; + return { reactionViewerRoot: null, pickedReaction }; }); }; @@ -1537,7 +1542,7 @@ export class Message extends React.PureComponent { someNotRendered && maybeNotRendered.some(res => res.some(re => Boolean(re.from.isMe))); - const { reactionViewerRoot, containerWidth } = this.state; + const { reactionViewerRoot, containerWidth, pickedReaction } = this.state; // Calculate the width of the reactions container const reactionsWidth = toRender.reduce((sum, res, i, arr) => { @@ -1598,7 +1603,10 @@ export class Message extends React.PureComponent { onClick={e => { e.stopPropagation(); e.preventDefault(); - this.toggleReactionViewer(); + this.toggleReactionViewer( + false, + isMore ? 'all' : re.emoji + ); }} onKeyDown={e => { // Prevent enter key from opening stickers/attachments @@ -1653,6 +1661,7 @@ export class Message extends React.PureComponent { zIndex: 2, }} reactions={reactions} + pickedReaction={pickedReaction} i18n={i18n} onClose={this.toggleReactionViewer} /> diff --git a/ts/components/conversation/ReactionViewer.md b/ts/components/conversation/ReactionViewer.md index b3881fe98e..cd522e969c 100644 --- a/ts/components/conversation/ReactionViewer.md +++ b/ts/components/conversation/ReactionViewer.md @@ -24,6 +24,31 @@ ``` +#### Picked Reaction + +```jsx + + + +``` + #### Many Reactions ```jsx diff --git a/ts/components/conversation/ReactionViewer.tsx b/ts/components/conversation/ReactionViewer.tsx index ae6943974c..80e93152ff 100644 --- a/ts/components/conversation/ReactionViewer.tsx +++ b/ts/components/conversation/ReactionViewer.tsx @@ -22,6 +22,7 @@ export type Reaction = { export type OwnProps = { reactions: Array; + pickedReaction?: string; onClose?: () => unknown; }; @@ -33,11 +34,11 @@ const emojisOrder = ['❤️', '👍', '👎', '😂', '😮', '😢', '😡']; export const ReactionViewer = React.forwardRef( // tslint:disable-next-line max-func-body-length - ({ i18n, reactions, onClose, ...rest }, ref) => { + ({ i18n, reactions, onClose, pickedReaction, ...rest }, ref) => { const grouped = mapValues(groupBy(reactions, 'emoji'), res => orderBy(res, ['timestamp'], ['desc']) ); - const [selected, setSelected] = React.useState('all'); + const [selected, setSelected] = React.useState(pickedReaction || 'all'); const focusRef = React.useRef(null); // Handle escape key @@ -77,7 +78,7 @@ export const ReactionViewer = React.forwardRef( }, [reactions]); const allSorted = React.useMemo(() => { - return sortBy(reactions, 'timestamp'); + return orderBy(reactions, ['timestamp'], ['desc']); }, [reactions]); // If we have previously selected a reaction type that is no longer present