Skip to content

Commit

Permalink
Fixing custom reaction functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalnarkhede committed Apr 21, 2020
1 parent b4f800c commit 5deea55
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions docs/cookbook.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,8 @@ Here I am aiming for following styles:
- Blue background
- white colored text

<img align="right" src="./images/6.png" alt="IMAGE ALT TEXT HERE" width="280" border="1" style="float: right;" />

```js
const MessageSimpleStyled = (props) => {
const { isMyMessage, message } = props;
Expand Down Expand Up @@ -214,6 +216,8 @@ const MessageSimpleStyled = (props) => {

In this example I will support only two reactions - Monkey face (🐵) and Lion (🦁)

<img align="right" src="./images/7.png" alt="IMAGE ALT TEXT HERE" width="280" border="1" style="float: right;" />

```js
const MessageSimpleWithCustomReactions = (props) => (
<MessageSimple
Expand Down Expand Up @@ -284,6 +288,8 @@ First you want to disable/hide the original reaction selector. `MessageSimple` c
UI component as prop - `ReactionList`. If you set this prop to null, then original reaction list and thus reaction selector
will be hidden/disabled

<img align="right" src="./images/8.png" alt="IMAGE ALT TEXT HERE" width="280" border="1" style="float: right;" />

```js static
const MessageWithoutReactionPicker = props => {
return (
Expand Down
Binary file added docs/images/6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/images/8.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/components/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,13 @@ const Message = withKeyboardContext(
if (dismissKeyboardOnMessageTouch) dismissKeyboard();
};

getTotalReactionCount = () => {
getTotalReactionCount = (supportedReactions) => {
const { emojiData } = this.props;
let count = null;
if (!supportedReactions) {
supportedReactions = emojiData;
}

const reactionCounts = this.props.message.reaction_counts;

if (
Expand All @@ -288,7 +292,7 @@ const Message = withKeyboardContext(
) {
count = 0;
Object.keys(reactionCounts).map((key) => {
if (emojiData.find((e) => e.id === key)) {
if (supportedReactions.find((e) => e.id === key)) {
count += reactionCounts[key];
}

Expand Down
6 changes: 4 additions & 2 deletions src/components/ReactionList.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ export const ReactionList = themed(
<Reactions>
{renderReactions(latestReactions, supportedReactions)}
</Reactions>
<ReactionCount reactionCounts={getTotalReactionCount()}>
{getTotalReactionCount()}
<ReactionCount
reactionCounts={getTotalReactionCount(supportedReactions)}
>
{getTotalReactionCount(supportedReactions)}
</ReactionCount>
</Container>
<ImageWrapper visible={visible}>
Expand Down
7 changes: 6 additions & 1 deletion types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -973,7 +973,12 @@ export interface MessageSystemProps
export interface ReactionListProps extends StyledComponentProps {
latestReactions: Client.ReactionResponse[];
openReactionSelector?(event: GestureResponderEvent): void;
getTotalReactionCount?(): string | number;
getTotalReactionCount?(
supportedReacions?: Array<{
icon: string;
id: string;
}>,
): string | number;
visible: boolean;
position: string;
supportedReactions?: Array<{
Expand Down

0 comments on commit 5deea55

Please sign in to comment.