Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Popover reaction list does not update dynamically #24024

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ function ReportActionItemEmojiReactions(props) {
};

const onReactionListOpen = (event) => {
reactionListRef.current.showReactionList(event, popoverReactionListAnchor.current, reactionEmojiName, props.reportActionID);
reactionListRef.current.setReactionListReportActionID(props.reportActionID);
reactionListRef.current.showReactionList(event, popoverReactionListAnchor.current, reactionEmojiName);
tienifr marked this conversation as resolved.
Show resolved Hide resolved
};

return {
Expand Down
29 changes: 22 additions & 7 deletions src/pages/home/report/ReactionList/PopoverReactionList/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
import React, {forwardRef, useImperativeHandle, useRef, useState} from 'react';
import PropTypes from "prop-types";
import BasePopoverReactionList from './BasePopoverReactionList';

const PopoverReactionList = forwardRef((props, ref) => {
const propTypes = {
ref: PropTypes.oneOfType([PropTypes.func, PropTypes.object]),
tienifr marked this conversation as resolved.
Show resolved Hide resolved
}

const defaultProps = {
ref: () => {},
}

function PopoverReactionList(props) {
const innerReactionListRef = useRef();
const [reactionListReportActionID, setReactionListReportActionID] = useState('');

Expand All @@ -11,23 +20,29 @@ const PopoverReactionList = forwardRef((props, ref) => {
* @param {Object} [event] - A press event.
* @param {Element} reactionListAnchor - reactionListAnchor
* @param {String} emojiName - Name of emoji
* @param {String} reportActionID
*/
const showReactionList = (event, reactionListAnchor, emojiName, reportActionID) => {
setReactionListReportActionID(reportActionID);
const showReactionList = (event, reactionListAnchor, emojiName) => {
innerReactionListRef.current.showReactionList(event, reactionListAnchor, emojiName);
tienifr marked this conversation as resolved.
Show resolved Hide resolved
};

useImperativeHandle(ref, () => ({showReactionList, setReactionListReportActionID}), []);
useImperativeHandle(props.ref, () => ({showReactionList, setReactionListReportActionID}), []);

return (
<BasePopoverReactionList
ref={innerReactionListRef}
reportActionID={reactionListReportActionID}
/>
);
});
}

PopoverReactionList.propTypes = propTypes;
PopoverReactionList.defaultProps = defaultProps;
PopoverReactionList.displayName = 'PopoverReactionList';
tienifr marked this conversation as resolved.
Show resolved Hide resolved

export default PopoverReactionList;
export default forwardRef((props, ref) => (
<PopoverReactionList
// eslint-disable-next-line react/jsx-props-no-spreading
{...props}
ref={ref}
/>
));
Loading