Skip to content

Commit

Permalink
highlight action when previous is a whisper
Browse files Browse the repository at this point in the history
  • Loading branch information
rezkiy37 committed Aug 7, 2023
1 parent 4c30fa3 commit 51adace
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions src/libs/ReportActionsUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,19 @@ function getExpandHoverArea(reportActions, actionIndex) {
return expandHoverArea;
}

/**
* A helper function to understand is the previous action a whisper
*
* @param {Array} reportActions
* @param {Number} actionIndex - index of the comment item in state to check
* @returns {Array<String>}
*/
function isPrevActionWhisper(reportActions, actionIndex) {
const prevAction = reportActions[actionIndex + 1];

return lodashGet(prevAction, 'whisperedToAccountIDs.length', 0) > 0;
}

export {
getSortedReportActions,
getLastVisibleAction,
Expand Down Expand Up @@ -619,4 +632,5 @@ export {
isPendingRemove,
getReportAction,
getExpandHoverArea,
isPrevActionWhisper,
};
8 changes: 6 additions & 2 deletions src/pages/home/report/ReportActionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,9 @@ const propTypes = {
* It gets strings: "top" and "bottom".
* */
expandHoverArea: PropTypes.arrayOf(PropTypes.string),

/** A value to understand is the previous action a whisper */
isPrevActionWhisper: PropTypes.bool,
};

const defaultProps = {
Expand All @@ -128,6 +131,7 @@ const defaultProps = {
shouldHideThreadDividerLine: false,
separatorActions: {},
expandHoverArea: [],
isPrevActionWhisper: false,
};

function ReportActionItem(props) {
Expand All @@ -151,15 +155,15 @@ function ReportActionItem(props) {
return;
}

if (isWhisper && props.displayAsGroup) {
if (isWhisper && (props.displayAsGroup || props.isPrevActionWhisper)) {
props.separatorActions.highlight();
} else {
props.separatorActions.unhighlight();
}
// This useEffect should be invoked as less as possible.
// It still has all dependencies, but tracks directly each value.
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isWhisper, props.displayAsGroup, props.separatorActions.highlight, props.separatorActions.unhighlight]);
}, [isWhisper, props.displayAsGroup, props.isPrevActionWhisper, props.separatorActions.highlight, props.separatorActions.unhighlight]);

useEffect(
() => () => {
Expand Down
1 change: 1 addition & 0 deletions src/pages/home/report/ReportActionsList.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ function ReportActionsList(props) {
unhighlight: separators.unhighlight,
}}
expandHoverArea={expandHoverArea}
isPrevActionWhisper={ReportActionsUtils.isPrevActionWhisper(sortedReportActions, index)}
/>
);
},
Expand Down

0 comments on commit 51adace

Please sign in to comment.