From 2d84c3d6cefc9f102feab16dacde13eda284062e Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 1 Apr 2024 17:42:01 +0700 Subject: [PATCH 01/12] fix unsubscribe is typing event if not focus on screen --- src/pages/home/report/ReportActionsList.tsx | 3 -- src/pages/home/report/ReportActionsView.tsx | 42 ++++++++++++++------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index d1b9c420b0af..ebe12143903e 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -351,9 +351,6 @@ function ReportActionsList({ if (unsubscribe) { unsubscribe(); } - InteractionManager.runAfterInteractions(() => { - Report.unsubscribeFromReportChannel(report.reportID); - }); }; newActionUnsubscribeMap[report.reportID] = cleanup; diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 1b6a9614a466..e8f7f77f7c05 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -12,6 +12,7 @@ import usePrevious from '@hooks/usePrevious'; import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; import getIsReportFullyVisible from '@libs/getIsReportFullyVisible'; +import Navigation from '@libs/Navigation/Navigation'; import type {CentralPaneNavigatorParamList} from '@libs/Navigation/types'; import * as NumberUtils from '@libs/NumberUtils'; import {generateNewRandomInt} from '@libs/NumberUtils'; @@ -324,21 +325,34 @@ function ReportActionsView({ if (route?.params?.reportID !== reportID) { return; } - // Ensures subscription event succeeds when the report/workspace room is created optimistically. - // Check if the optimistic `OpenReport` or `AddWorkspaceRoom` has succeeded by confirming - // any `pendingFields.createChat` or `pendingFields.addWorkspaceRoom` fields are set to null. - // Existing reports created will have empty fields for `pendingFields`. - const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat); - if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) { - const interactionTask = InteractionManager.runAfterInteractions(() => { - Report.subscribeToReportTypingEvents(reportID); - didSubscribeToReportTypingEvents.current = true; - }); - return () => { - interactionTask.cancel(); - }; + + if (isFocused) { + // Ensures subscription event succeeds when the report/workspace room is created optimistically. + // Check if the optimistic `OpenReport` or `AddWorkspaceRoom` has succeeded by confirming + // any `pendingFields.createChat` or `pendingFields.addWorkspaceRoom` fields are set to null. + // Existing reports created will have empty fields for `pendingFields`. + const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat); + + if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) { + const interactionTask = InteractionManager.runAfterInteractions(() => { + Report.subscribeToReportTypingEvents(reportID); + didSubscribeToReportTypingEvents.current = true; + }); + return () => { + interactionTask.cancel(); + }; + } + } else { + const topmostReportId = Navigation.getTopmostReportId(); + + if (topmostReportId !== report.reportID && didSubscribeToReportTypingEvents.current) { + didSubscribeToReportTypingEvents.current = false; + InteractionManager.runAfterInteractions(() => { + Report.unsubscribeFromReportChannel(report.reportID); + }); + } } - }, [report.pendingFields, didSubscribeToReportTypingEvents, route, reportID]); + }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, route, reportID]); const onContentSizeChange = useCallback((w: number, h: number) => { contentListHeight.current = h; From 72287935975b1316e55b537b62869ed8aa6f5151 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 1 Apr 2024 18:03:27 +0700 Subject: [PATCH 02/12] fix lint --- src/pages/home/report/ReportActionsList.tsx | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/ReportActionsList.tsx b/src/pages/home/report/ReportActionsList.tsx index ebe12143903e..ee32c3c2ff61 100644 --- a/src/pages/home/report/ReportActionsList.tsx +++ b/src/pages/home/report/ReportActionsList.tsx @@ -348,9 +348,10 @@ function ReportActionsList({ const unsubscribe = Report.subscribeToNewActionEvent(report.reportID, scrollToBottomForCurrentUserAction); const cleanup = () => { - if (unsubscribe) { - unsubscribe(); + if (!unsubscribe) { + return; } + unsubscribe(); }; newActionUnsubscribeMap[report.reportID] = cleanup; From 1ca5ac0a9b3dda55c780dd23553442f6661eabac Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 5 Apr 2024 06:46:53 +0700 Subject: [PATCH 03/12] fix isTyping is not unsubscribe when searching --- src/pages/home/report/ReportActionsView.tsx | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index e8f7f77f7c05..d694260a2a58 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -43,6 +43,9 @@ type ReportActionsViewOnyxProps = { /** The transaction thread report associated with the current report, if any */ transactionThreadReport: OnyxEntry; + + /** Stores last visited path */ + lastVisitedPath?: string; }; type ReportActionsViewProps = ReportActionsViewOnyxProps & { @@ -88,6 +91,7 @@ function ReportActionsView({ isLoadingOlderReportActions = false, isLoadingNewerReportActions = false, isReadyForCommentLinking = false, + lastVisitedPath, }: ReportActionsViewProps) { useCopySelectionHelper(); const reactionListRef = useContext(ReactionListContext); @@ -352,7 +356,7 @@ function ReportActionsView({ }); } } - }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, route, reportID]); + }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, route, reportID, lastVisitedPath]); const onContentSizeChange = useCallback((w: number, h: number) => { contentListHeight.current = h; @@ -628,5 +632,8 @@ export default Performance.withRenderTrace({id: ' rendering'} transactionThreadReport: { key: ({transactionThreadReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, }, + lastVisitedPath: { + key: ONYXKEYS.LAST_VISITED_PATH, + }, })(MemoizedReportActionsView), ); From f4c2dde0879ec2ad05be73095a13bb07ce4a1a08 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 5 Apr 2024 07:04:13 +0700 Subject: [PATCH 04/12] fix lint --- src/pages/home/report/ReportActionsView.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index d694260a2a58..1ee8b3edd235 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -634,6 +634,7 @@ export default Performance.withRenderTrace({id: ' rendering'} }, lastVisitedPath: { key: ONYXKEYS.LAST_VISITED_PATH, + selector: (path) => path ?? '', }, })(MemoizedReportActionsView), ); From 9f94a2dd123cdefc6a9a9c48d4f57a6b1545aa06 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 5 Apr 2024 17:40:17 +0700 Subject: [PATCH 05/12] fix arePropsEqual func --- src/pages/home/report/ReportActionsView.tsx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 1ee8b3edd235..de40c0d07f0f 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -356,7 +356,7 @@ function ReportActionsView({ }); } } - }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, route, reportID, lastVisitedPath]); + }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, route, reportID]); const onContentSizeChange = useCallback((w: number, h: number) => { contentListHeight.current = h; @@ -614,6 +614,9 @@ function arePropsEqual(oldProps: ReportActionsViewProps, newProps: ReportActions return false; } + if (oldProps.lastVisitedPath !== newProps.lastVisitedPath) { + return false; + } return lodashIsEqual(oldProps.report, newProps.report); } From 61ff8a3df9c5f85d1a5075957db010e016ecf050 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 5 Apr 2024 17:47:17 +0700 Subject: [PATCH 06/12] fix deps --- src/pages/home/report/ReportActionsView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index de40c0d07f0f..7a3c70e1372b 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -356,7 +356,7 @@ function ReportActionsView({ }); } } - }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, route, reportID]); + }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID]); const onContentSizeChange = useCallback((w: number, h: number) => { contentListHeight.current = h; From 96453137eb215cad0bff46093083c443df12d981 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 5 Apr 2024 17:59:04 +0700 Subject: [PATCH 07/12] fix lint --- src/pages/home/report/ReportActionsView.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 7a3c70e1372b..7f7d9e7fe62b 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -356,7 +356,7 @@ function ReportActionsView({ }); } } - }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID]); + }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID, route]); const onContentSizeChange = useCallback((w: number, h: number) => { contentListHeight.current = h; From 231bb81e6480d8e4bf61b1725544bd1980ba4de0 Mon Sep 17 00:00:00 2001 From: tienifr Date: Fri, 5 Apr 2024 18:24:42 +0700 Subject: [PATCH 08/12] fix create UserTypingEventListener component --- src/pages/home/report/ReportActionsView.tsx | 53 ++------------ .../home/report/UserTypingEventListener.tsx | 71 +++++++++++++++++++ 2 files changed, 75 insertions(+), 49 deletions(-) create mode 100644 src/pages/home/report/UserTypingEventListener.tsx diff --git a/src/pages/home/report/ReportActionsView.tsx b/src/pages/home/report/ReportActionsView.tsx index 7f7d9e7fe62b..8d8ebcaaf721 100755 --- a/src/pages/home/report/ReportActionsView.tsx +++ b/src/pages/home/report/ReportActionsView.tsx @@ -3,8 +3,8 @@ import {useIsFocused, useRoute} from '@react-navigation/native'; import lodashIsEqual from 'lodash/isEqual'; import React, {useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState} from 'react'; import {InteractionManager} from 'react-native'; -import {withOnyx} from 'react-native-onyx'; import type {OnyxEntry} from 'react-native-onyx'; +import {withOnyx} from 'react-native-onyx'; import useCopySelectionHelper from '@hooks/useCopySelectionHelper'; import useInitialValue from '@hooks/useInitialValue'; import useNetwork from '@hooks/useNetwork'; @@ -12,14 +12,13 @@ import usePrevious from '@hooks/usePrevious'; import useWindowDimensions from '@hooks/useWindowDimensions'; import DateUtils from '@libs/DateUtils'; import getIsReportFullyVisible from '@libs/getIsReportFullyVisible'; -import Navigation from '@libs/Navigation/Navigation'; import type {CentralPaneNavigatorParamList} from '@libs/Navigation/types'; import * as NumberUtils from '@libs/NumberUtils'; import {generateNewRandomInt} from '@libs/NumberUtils'; import Performance from '@libs/Performance'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; -import {isUserCreatedPolicyRoom} from '@libs/ReportUtils'; import * as ReportUtils from '@libs/ReportUtils'; +import {isUserCreatedPolicyRoom} from '@libs/ReportUtils'; import {didUserLogInDuringSession} from '@libs/SessionUtils'; import shouldFetchReport from '@libs/shouldFetchReport'; import {ReactionListContext} from '@pages/home/ReportScreenContext'; @@ -33,6 +32,7 @@ import {isEmptyObject} from '@src/types/utils/EmptyObject'; import getInitialPaginationSize from './getInitialPaginationSize'; import PopoverReactionList from './ReactionList/PopoverReactionList'; import ReportActionsList from './ReportActionsList'; +import UserTypingEventListener from './UserTypingEventListener'; type ReportActionsViewOnyxProps = { /** Session info for the currently logged in user. */ @@ -43,9 +43,6 @@ type ReportActionsViewOnyxProps = { /** The transaction thread report associated with the current report, if any */ transactionThreadReport: OnyxEntry; - - /** Stores last visited path */ - lastVisitedPath?: string; }; type ReportActionsViewProps = ReportActionsViewOnyxProps & { @@ -91,14 +88,12 @@ function ReportActionsView({ isLoadingOlderReportActions = false, isLoadingNewerReportActions = false, isReadyForCommentLinking = false, - lastVisitedPath, }: ReportActionsViewProps) { useCopySelectionHelper(); const reactionListRef = useContext(ReactionListContext); const route = useRoute>(); const reportActionID = route?.params?.reportActionID; const didLayout = useRef(false); - const didSubscribeToReportTypingEvents = useRef(false); // triggerListID is used when navigating to a chat with messages loaded from LHN. Typically, these include thread actions, task actions, etc. Since these messages aren't the latest,we don't maintain their position and instead trigger a recalculation of their positioning in the list. // we don't set currentReportActionID on initial render as linkedID as it should trigger visibleReportActions after linked message was positioned @@ -324,40 +319,6 @@ function ReportActionsView({ // eslint-disable-next-line react-hooks/exhaustive-deps }, [isSmallScreenWidth, reportActions, isReportFullyVisible]); - useEffect(() => { - // Ensures the optimistic report is created successfully - if (route?.params?.reportID !== reportID) { - return; - } - - if (isFocused) { - // Ensures subscription event succeeds when the report/workspace room is created optimistically. - // Check if the optimistic `OpenReport` or `AddWorkspaceRoom` has succeeded by confirming - // any `pendingFields.createChat` or `pendingFields.addWorkspaceRoom` fields are set to null. - // Existing reports created will have empty fields for `pendingFields`. - const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat); - - if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) { - const interactionTask = InteractionManager.runAfterInteractions(() => { - Report.subscribeToReportTypingEvents(reportID); - didSubscribeToReportTypingEvents.current = true; - }); - return () => { - interactionTask.cancel(); - }; - } - } else { - const topmostReportId = Navigation.getTopmostReportId(); - - if (topmostReportId !== report.reportID && didSubscribeToReportTypingEvents.current) { - didSubscribeToReportTypingEvents.current = false; - InteractionManager.runAfterInteractions(() => { - Report.unsubscribeFromReportChannel(report.reportID); - }); - } - } - }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID, route]); - const onContentSizeChange = useCallback((w: number, h: number) => { contentListHeight.current = h; }, []); @@ -574,6 +535,7 @@ function ReportActionsView({ onContentSizeChange={onContentSizeChange} shouldEnableAutoScrollToTopThreshold={shouldEnableAutoScroll} /> + ); @@ -614,9 +576,6 @@ function arePropsEqual(oldProps: ReportActionsViewProps, newProps: ReportActions return false; } - if (oldProps.lastVisitedPath !== newProps.lastVisitedPath) { - return false; - } return lodashIsEqual(oldProps.report, newProps.report); } @@ -635,9 +594,5 @@ export default Performance.withRenderTrace({id: ' rendering'} transactionThreadReport: { key: ({transactionThreadReportID}) => `${ONYXKEYS.COLLECTION.REPORT}${transactionThreadReportID}`, }, - lastVisitedPath: { - key: ONYXKEYS.LAST_VISITED_PATH, - selector: (path) => path ?? '', - }, })(MemoizedReportActionsView), ); diff --git a/src/pages/home/report/UserTypingEventListener.tsx b/src/pages/home/report/UserTypingEventListener.tsx new file mode 100644 index 000000000000..649ec7ce5742 --- /dev/null +++ b/src/pages/home/report/UserTypingEventListener.tsx @@ -0,0 +1,71 @@ +import type {RouteProp} from '@react-navigation/native'; +import {useIsFocused, useRoute} from '@react-navigation/native'; +import {useEffect, useRef} from 'react'; +import {InteractionManager} from 'react-native'; +import {withOnyx} from 'react-native-onyx'; +import Navigation from '@libs/Navigation/Navigation'; +import type {CentralPaneNavigatorParamList} from '@libs/Navigation/types'; +import * as Report from '@userActions/Report'; +import ONYXKEYS from '@src/ONYXKEYS'; +import type SCREENS from '@src/SCREENS'; +import type * as OnyxTypes from '@src/types/onyx'; + +type UserTypingEventListenerOnyxProps = { + /** Stores last visited path */ + lastVisitedPath?: string; +}; + +type UserTypingEventListenerProps = UserTypingEventListenerOnyxProps & { + /** The report currently being looked at */ + report: OnyxTypes.Report; +}; +function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListenerProps) { + const didSubscribeToReportTypingEvents = useRef(false); + const reportID = report.reportID; + const isFocused = useIsFocused(); + const route = useRoute>(); + useEffect(() => { + // Ensures the optimistic report is created successfully + if (route?.params?.reportID !== reportID) { + return; + } + + if (isFocused) { + // Ensures subscription event succeeds when the report/workspace room is created optimistically. + // Check if the optimistic `OpenReport` or `AddWorkspaceRoom` has succeeded by confirming + // any `pendingFields.createChat` or `pendingFields.addWorkspaceRoom` fields are set to null. + // Existing reports created will have empty fields for `pendingFields`. + const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat); + + if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) { + const interactionTask = InteractionManager.runAfterInteractions(() => { + Report.subscribeToReportTypingEvents(reportID); + didSubscribeToReportTypingEvents.current = true; + }); + return () => { + interactionTask.cancel(); + }; + } + } else { + const topmostReportId = Navigation.getTopmostReportId(); + + if (topmostReportId !== report.reportID && didSubscribeToReportTypingEvents.current) { + didSubscribeToReportTypingEvents.current = false; + InteractionManager.runAfterInteractions(() => { + Report.unsubscribeFromReportChannel(report.reportID); + }); + } + } + }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID, route]); + + return null; +} + +UserTypingEventListener.displayName = 'UserTypingEventListener'; + +export default withOnyx({ + lastVisitedPath: { + key: ONYXKEYS.LAST_VISITED_PATH, + selector: (path) => path ?? '', + }, +})(UserTypingEventListener); From 421b27d5411ee323b86faa8e6ef0d808d8714471 Mon Sep 17 00:00:00 2001 From: tienifr Date: Wed, 10 Apr 2024 10:40:45 +0700 Subject: [PATCH 09/12] fix use reportID instead of report.reportID --- src/pages/home/report/UserTypingEventListener.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/home/report/UserTypingEventListener.tsx b/src/pages/home/report/UserTypingEventListener.tsx index 649ec7ce5742..2f00ef611515 100644 --- a/src/pages/home/report/UserTypingEventListener.tsx +++ b/src/pages/home/report/UserTypingEventListener.tsx @@ -49,14 +49,14 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe } else { const topmostReportId = Navigation.getTopmostReportId(); - if (topmostReportId !== report.reportID && didSubscribeToReportTypingEvents.current) { + if (topmostReportId !== reportID && didSubscribeToReportTypingEvents.current) { didSubscribeToReportTypingEvents.current = false; InteractionManager.runAfterInteractions(() => { - Report.unsubscribeFromReportChannel(report.reportID); + Report.unsubscribeFromReportChannel(reportID); }); } } - }, [isFocused, report.reportID, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID, route]); + }, [isFocused, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID, route]); return null; } From 810dd3a1322fe47704bd9088679656dcf5e361f3 Mon Sep 17 00:00:00 2001 From: Tienifr <113963320+tienifr@users.noreply.github.com> Date: Wed, 10 Apr 2024 16:43:28 +0700 Subject: [PATCH 10/12] fix update coment Co-authored-by: Alex Beaman --- src/pages/home/report/UserTypingEventListener.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/report/UserTypingEventListener.tsx b/src/pages/home/report/UserTypingEventListener.tsx index 2f00ef611515..17b09c445d54 100644 --- a/src/pages/home/report/UserTypingEventListener.tsx +++ b/src/pages/home/report/UserTypingEventListener.tsx @@ -25,7 +25,7 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe const isFocused = useIsFocused(); const route = useRoute>(); useEffect(() => { - // Ensures the optimistic report is created successfully + // Ensures any optimistic report that is being created (ex: a thread report) gets created and initialized successfully before subscribing if (route?.params?.reportID !== reportID) { return; } From 9b09b3165f00f4e7e3f5dd8742475d6d3b43837f Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 15 Apr 2024 13:11:34 +0700 Subject: [PATCH 11/12] fix jest test 3 --- src/pages/home/report/UserTypingEventListener.tsx | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pages/home/report/UserTypingEventListener.tsx b/src/pages/home/report/UserTypingEventListener.tsx index 17b09c445d54..5aa9a0371840 100644 --- a/src/pages/home/report/UserTypingEventListener.tsx +++ b/src/pages/home/report/UserTypingEventListener.tsx @@ -38,13 +38,10 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat); if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) { - const interactionTask = InteractionManager.runAfterInteractions(() => { + InteractionManager.runAfterInteractions(() => { Report.subscribeToReportTypingEvents(reportID); didSubscribeToReportTypingEvents.current = true; }); - return () => { - interactionTask.cancel(); - }; } } else { const topmostReportId = Navigation.getTopmostReportId(); From 025dc64bd09b09c144b424820e2f0c8b60c03423 Mon Sep 17 00:00:00 2001 From: tienifr Date: Mon, 15 Apr 2024 16:42:52 +0700 Subject: [PATCH 12/12] fix jest test --- src/pages/home/report/UserTypingEventListener.tsx | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/pages/home/report/UserTypingEventListener.tsx b/src/pages/home/report/UserTypingEventListener.tsx index 5aa9a0371840..45e56cfe7ff1 100644 --- a/src/pages/home/report/UserTypingEventListener.tsx +++ b/src/pages/home/report/UserTypingEventListener.tsx @@ -29,7 +29,7 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe if (route?.params?.reportID !== reportID) { return; } - + let interactionTask: ReturnType | null = null; if (isFocused) { // Ensures subscription event succeeds when the report/workspace room is created optimistically. // Check if the optimistic `OpenReport` or `AddWorkspaceRoom` has succeeded by confirming @@ -38,7 +38,7 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe const didCreateReportSuccessfully = !report.pendingFields || (!report.pendingFields.addWorkspaceRoom && !report.pendingFields.createChat); if (!didSubscribeToReportTypingEvents.current && didCreateReportSuccessfully) { - InteractionManager.runAfterInteractions(() => { + interactionTask = InteractionManager.runAfterInteractions(() => { Report.subscribeToReportTypingEvents(reportID); didSubscribeToReportTypingEvents.current = true; }); @@ -53,6 +53,12 @@ function UserTypingEventListener({report, lastVisitedPath}: UserTypingEventListe }); } } + return () => { + if (!interactionTask) { + return; + } + interactionTask.cancel(); + }; }, [isFocused, report.pendingFields, didSubscribeToReportTypingEvents, lastVisitedPath, reportID, route]); return null;