From 87ad389ad009b6b7bd788e4950f3d73e23406d45 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 27 Oct 2023 12:44:36 +0700 Subject: [PATCH 1/3] fix: 30457 --- src/pages/home/report/ReportActionsView.js | 32 +++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index 108e75051696..d18f55d854be 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -21,6 +21,10 @@ import PopoverReactionList from './ReactionList/PopoverReactionList'; import getIsReportFullyVisible from '../../../libs/getIsReportFullyVisible'; import {ReactionListContext} from '../ReportScreenContext'; import useInitialValue from '../../../hooks/useInitialValue'; +import { withOnyx } from 'react-native-onyx'; +import ONYXKEYS from '../../../ONYXKEYS'; +import { didUserLogInDuringSession } from '../../../libs/SessionUtils'; +import { isUserCreatedPolicyRoom } from '../../../libs/ReportUtils'; const propTypes = { /** The report currently being looked at */ @@ -64,6 +68,9 @@ const defaultProps = { isLoadingInitialReportActions: false, isLoadingOlderReportActions: false, isLoadingNewerReportActions: false, + session:{ + authTokenType: '' + } }; function ReportActionsView(props) { @@ -76,6 +83,8 @@ function ReportActionsView(props) { const mostRecentIOUReportActionID = useInitialValue(() => ReportActionsUtils.getMostRecentIOURequestActionID(props.reportActions)); const prevNetworkRef = useRef(props.network); + const prevAuthTokenType = useRef(props.session.authTokenType); + const prevIsSmallScreenWidthRef = useRef(props.isSmallScreenWidth); const isFocused = useIsFocused(); @@ -118,6 +127,21 @@ function ReportActionsView(props) { // eslint-disable-next-line react-hooks/exhaustive-deps }, [props.network, props.report, isReportFullyVisible]); + useEffect(() => { + const prevTokenType = prevAuthTokenType.current; + const wasLoginChangedDetected = prevTokenType === 'anonymousAccount' && !props.session.authTokenType + if (wasLoginChangedDetected && didUserLogInDuringSession() && isUserCreatedPolicyRoom(props.report)) { + if (isReportFullyVisible) { + openReportIfNecessary(); + } else { + Report.reconnect(reportID); + } + } + // update ref with current network state + prevAuthTokenType.current = props.session.authTokenType; + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [props.session, props.report, isReportFullyVisible]); + useEffect(() => { const prevIsSmallScreenWidth = prevIsSmallScreenWidthRef.current; // If the view is expanded from mobile to desktop layout @@ -338,4 +362,10 @@ function arePropsEqual(oldProps, newProps) { const MemoizedReportActionsView = React.memo(ReportActionsView, arePropsEqual); -export default compose(Performance.withRenderTrace({id: ' rendering'}), withWindowDimensions, withLocalize, withNetwork())(MemoizedReportActionsView); +export default compose(Performance.withRenderTrace({id: ' rendering'}), withWindowDimensions, withLocalize, withNetwork(), +withOnyx({ + session: { + key: ONYXKEYS.SESSION, + }, +}) +)(MemoizedReportActionsView); From bf322ac3816196383668c09f77a1408489a8b14d Mon Sep 17 00:00:00 2001 From: tienifr Date: Thu, 2 Nov 2023 16:49:37 +0700 Subject: [PATCH 2/3] add session to memo dependencies --- src/pages/home/report/ReportActionsView.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index eee3e3eeedae..4a95157224a4 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -143,7 +143,6 @@ function ReportActionsView(props) { Report.reconnect(reportID); } } - // update ref with current network state prevAuthTokenType.current = props.session.authTokenType; // eslint-disable-next-line react-hooks/exhaustive-deps }, [props.session, props.report, isReportFullyVisible]); @@ -291,6 +290,10 @@ function arePropsEqual(oldProps, newProps) { return false; } + if (lodashGet(oldProps.session, 'authTokenType') !== lodashGet(newProps.session, 'authTokenType')) { + return false; + } + if (oldProps.isLoadingInitialReportActions !== newProps.isLoadingInitialReportActions) { return false; } From d75501f485c7a8668f13eb09fca56e6281716335 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 6 Nov 2023 16:20:37 +0700 Subject: [PATCH 3/3] use usePrevious --- src/pages/home/report/ReportActionsView.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/home/report/ReportActionsView.js b/src/pages/home/report/ReportActionsView.js index b07a79d49635..28ddcd94dfb2 100755 --- a/src/pages/home/report/ReportActionsView.js +++ b/src/pages/home/report/ReportActionsView.js @@ -10,6 +10,7 @@ import withLocalize, {withLocalizePropTypes} from '@components/withLocalize'; import withWindowDimensions, {windowDimensionsPropTypes} from '@components/withWindowDimensions'; import useCopySelectionHelper from '@hooks/useCopySelectionHelper'; import useInitialValue from '@hooks/useInitialValue'; +import usePrevious from '@hooks/usePrevious'; import compose from '@libs/compose'; import getIsReportFullyVisible from '@libs/getIsReportFullyVisible'; import Performance from '@libs/Performance'; @@ -89,7 +90,7 @@ function ReportActionsView(props) { const mostRecentIOUReportActionID = useInitialValue(() => ReportActionsUtils.getMostRecentIOURequestActionID(props.reportActions)); const prevNetworkRef = useRef(props.network); - const prevAuthTokenType = useRef(props.session.authTokenType); + const prevAuthTokenType = usePrevious(props.session.authTokenType); const prevIsSmallScreenWidthRef = useRef(props.isSmallScreenWidth); @@ -134,8 +135,7 @@ function ReportActionsView(props) { }, [props.network, props.report, isReportFullyVisible]); useEffect(() => { - const prevTokenType = prevAuthTokenType.current; - const wasLoginChangedDetected = prevTokenType === 'anonymousAccount' && !props.session.authTokenType; + const wasLoginChangedDetected = prevAuthTokenType === 'anonymousAccount' && !props.session.authTokenType; if (wasLoginChangedDetected && didUserLogInDuringSession() && isUserCreatedPolicyRoom(props.report)) { if (isReportFullyVisible) { openReportIfNecessary(); @@ -143,7 +143,6 @@ function ReportActionsView(props) { Report.reconnect(reportID); } } - prevAuthTokenType.current = props.session.authTokenType; // eslint-disable-next-line react-hooks/exhaustive-deps }, [props.session, props.report, isReportFullyVisible]);