diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 398fd16bb734..2661a20c400d 100644 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -26,6 +26,9 @@ import Visibility from '../../../libs/Visibility'; import Timing from '../../../libs/actions/Timing'; import CONST from '../../../CONST'; import themeColors from '../../../styles/themes/default'; +import compose from '../../../libs/compose'; +import withWindowDimensions, {windowDimensionsPropTypes} from '../../../components/withWindowDimensions'; +import withDrawerState, {withDrawerPropTypes} from '../../../components/withDrawerState'; const propTypes = { // The ID of the report actions will be created for @@ -56,6 +59,9 @@ const propTypes = { // Email of the logged in person email: PropTypes.string, }), + + ...windowDimensionsPropTypes, + ...withDrawerPropTypes, }; const defaultProps = { @@ -78,6 +84,7 @@ class ReportActionsView extends React.Component { this.recordMaxAction = this.recordMaxAction.bind(this); this.onVisibilityChange = this.onVisibilityChange.bind(this); this.loadMoreChats = this.loadMoreChats.bind(this); + this.startRecordMaxActionTimer = this.startRecordMaxActionTimer.bind(this); this.sortedReportActions = []; this.timers = []; @@ -113,6 +120,14 @@ class ReportActionsView extends React.Component { return true; } + if (this.props.isSmallScreenWidth !== nextProps.isSmallScreenWidth) { + return true; + } + + if (this.props.isDrawerOpen !== nextProps.isDrawerOpen) { + return true; + } + if (this.props.report.hasOutstandingIOU !== nextProps.report.hasOutstandingIOU || this.props.report.iouReportID !== nextProps.report.iouReportID) { return true; @@ -125,6 +140,9 @@ class ReportActionsView extends React.Component { // The last sequenceNumber of the same report has changed. const previousLastSequenceNumber = lodashGet(lastItem(prevProps.reportActions), 'sequenceNumber'); const currentLastSequenceNumber = lodashGet(lastItem(this.props.reportActions), 'sequenceNumber'); + const shouldRecordMaxAction = Visibility.isVisible() + && !(this.props.isDrawerOpen && this.props.isSmallScreenWidth); + if (previousLastSequenceNumber !== currentLastSequenceNumber) { // If a new comment is added and it's from the current user scroll to the bottom otherwise // leave the user positioned where they are now in the list. @@ -135,10 +153,19 @@ class ReportActionsView extends React.Component { // When the last action changes, wait three seconds, then record the max action // This will make the unread indicator go away if you receive comments in the same chat you're looking at - if (Visibility.isVisible()) { - this.timers.push(setTimeout(this.recordMaxAction, 3000)); + if (shouldRecordMaxAction) { + this.startRecordMaxActionTimer(); } } + + // We want to mark the unread comments when user resize the screen to desktop + // Or user move back to report from LHN + if (shouldRecordMaxAction && ( + prevProps.isDrawerOpen !== this.props.isDrawerOpen + || prevProps.isSmallScreenWidth !== this.props.isSmallScreenWidth + )) { + this.startRecordMaxActionTimer(); + } } componentWillUnmount() { @@ -157,10 +184,19 @@ class ReportActionsView extends React.Component { */ onVisibilityChange() { if (Visibility.isVisible()) { - this.timers.push(setTimeout(this.recordMaxAction, 3000)); + this.startRecordMaxActionTimer(); } } + /** + * Set a timer for recording the max action + * + * @memberof ReportActionsView + */ + startRecordMaxActionTimer() { + this.timers.push(setTimeout(this.recordMaxAction, 3000)); + } + /** * Retrieves the next set of report actions for the chat once we are nearing the end of what we are currently * displaying. @@ -357,15 +393,19 @@ class ReportActionsView extends React.Component { ReportActionsView.propTypes = propTypes; ReportActionsView.defaultProps = defaultProps; -export default withOnyx({ - report: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, - }, - reportActions: { - key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, - canEvict: false, - }, - session: { - key: ONYXKEYS.SESSION, - }, -})(ReportActionsView); +export default compose( + withWindowDimensions, + withDrawerState, + withOnyx({ + report: { + key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT}${reportID}`, + }, + reportActions: { + key: ({reportID}) => `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`, + canEvict: false, + }, + session: { + key: ONYXKEYS.SESSION, + }, + }), +)(ReportActionsView);