Skip to content

Commit

Permalink
[native] switch getViewerAlreadySelectedMessageReactions to useGetVie…
Browse files Browse the repository at this point in the history
…werAlreadySelectedMessageReactions

Summary: small follow up diff to address comment in D8288

Test Plan: confirmed that the already selected emojis still behaved as expected in the emoji keyboard

Reviewers: atul, kamil

Reviewed By: kamil

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D8410
  • Loading branch information
ginsueddy committed Jul 5, 2023
1 parent 63eac31 commit 864aeee
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 24 deletions.
20 changes: 11 additions & 9 deletions lib/shared/reaction-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,22 @@ function stringForReactionList(reactions: ReactionInfo): string {
return reactionText.join(' ');
}

function getViewerAlreadySelectedMessageReactions(
function useViewerAlreadySelectedMessageReactions(
reactions: ReactionInfo,
): $ReadOnlyArray<string> {
const alreadySelectedEmojis = [];
return React.useMemo(() => {
const alreadySelectedEmojis = [];

for (const reaction in reactions) {
const reactionInfo = reactions[reaction];
for (const reaction in reactions) {
const reactionInfo = reactions[reaction];

if (reactionInfo.viewerReacted) {
alreadySelectedEmojis.push(reaction);
if (reactionInfo.viewerReacted) {
alreadySelectedEmojis.push(reaction);
}
}
}

return alreadySelectedEmojis;
return alreadySelectedEmojis;
}, [reactions]);
}

type MessageReactionListInfo = {
Expand Down Expand Up @@ -119,7 +121,7 @@ function useCanCreateReactionFromMessage(

export {
stringForReactionList,
getViewerAlreadySelectedMessageReactions,
useViewerAlreadySelectedMessageReactions,
useMessageReactionsList,
useCanCreateReactionFromMessage,
};
8 changes: 3 additions & 5 deletions native/chat/multimedia-message-tooltip-button.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Animated from 'react-native-reanimated';

import { localIDPrefix } from 'lib/shared/message-utils.js';
import {
getViewerAlreadySelectedMessageReactions,
useViewerAlreadySelectedMessageReactions,
useCanCreateReactionFromMessage,
} from 'lib/shared/reaction-utils.js';

Expand Down Expand Up @@ -155,10 +155,8 @@ function MultimediaMessageTooltipButton(props: Props): React.Node {
[sendReaction, dismissTooltip],
);

const alreadySelectedEmojis = React.useMemo(
() => getViewerAlreadySelectedMessageReactions(item.reactions),
[item.reactions],
);
const alreadySelectedEmojis =
useViewerAlreadySelectedMessageReactions(reactions);

return (
<>
Expand Down
8 changes: 3 additions & 5 deletions native/chat/robotext-message-tooltip-button.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Animated from 'react-native-reanimated';

import { localIDPrefix } from 'lib/shared/message-utils.js';
import {
getViewerAlreadySelectedMessageReactions,
useViewerAlreadySelectedMessageReactions,
useCanCreateReactionFromMessage,
} from 'lib/shared/reaction-utils.js';

Expand Down Expand Up @@ -138,10 +138,8 @@ function RobotextMessageTooltipButton(props: Props): React.Node {
[sendReaction, dismissTooltip],
);

const alreadySelectedEmojis = React.useMemo(
() => getViewerAlreadySelectedMessageReactions(item.reactions),
[item.reactions],
);
const alreadySelectedEmojis =
useViewerAlreadySelectedMessageReactions(reactions);

return (
<>
Expand Down
8 changes: 3 additions & 5 deletions native/chat/text-message-tooltip-button.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Animated from 'react-native-reanimated';

import { localIDPrefix } from 'lib/shared/message-utils.js';
import {
getViewerAlreadySelectedMessageReactions,
useViewerAlreadySelectedMessageReactions,
useCanCreateReactionFromMessage,
} from 'lib/shared/reaction-utils.js';

Expand Down Expand Up @@ -152,10 +152,8 @@ function TextMessageTooltipButton(props: Props): React.Node {
[sendReaction, dismissTooltip],
);

const alreadySelectedEmojis = React.useMemo(
() => getViewerAlreadySelectedMessageReactions(item.reactions),
[item.reactions],
);
const alreadySelectedEmojis =
useViewerAlreadySelectedMessageReactions(reactions);

return (
<MessageListContextProvider threadInfo={threadInfo}>
Expand Down

0 comments on commit 864aeee

Please sign in to comment.