From 08337c3bc03cea5a74ee0aa22818826fb3f4b964 Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Wed, 20 Sep 2023 15:31:39 +0700 Subject: [PATCH 1/3] leave room when has no comment --- src/libs/actions/Report.js | 11 +++++++---- src/pages/home/ReportScreen.js | 15 ++++++++++++++- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index 2a34c839a94ec..759f245ac0a5e 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1777,8 +1777,9 @@ function getCurrentUserAccountID() { * Leave a report by setting the state to submitted and closed * * @param {String} reportID + * @param {Boolean} shouldNavigate should navigate after leaving room or not */ -function leaveRoom(reportID) { +function leaveRoom(reportID, shouldNavigate = true) { const report = lodashGet(allReports, [reportID], {}); const reportKeys = _.keys(report); API.write( @@ -1819,10 +1820,12 @@ function leaveRoom(reportID) { }, ); Navigation.dismissModal(); - if (Navigation.getTopmostReportId() === reportID) { - Navigation.goBack(); + if (shouldNavigate) { + if (Navigation.getTopmostReportId() === reportID) { + Navigation.goBack(); + } + navigateToConciergeChat(); } - navigateToConciergeChat(); } /** diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 8528b8f213a93..13e77923ad5cd 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -1,6 +1,6 @@ import React, {useRef, useState, useEffect, useMemo, useCallback} from 'react'; import {withOnyx} from 'react-native-onyx'; -import {useFocusEffect} from '@react-navigation/native'; +import {useFocusEffect, useIsFocused} from '@react-navigation/native'; import PropTypes from 'prop-types'; import {View} from 'react-native'; import lodashGet from 'lodash/get'; @@ -151,6 +151,7 @@ function ReportScreen({ const flatListRef = useRef(); const reactionListRef = useRef(); const prevReport = usePrevious(report); + const isFocused = useIsFocused(); const [skeletonViewContainerHeight, setSkeletonViewContainerHeight] = useState(0); const [isBannerVisible, setIsBannerVisible] = useState(true); @@ -312,6 +313,18 @@ function ReportScreen({ [report, isLoading, shouldHideReport, isDefaultReport, isOptimisticDelete], ); + useEffect(() => { + if (isFocused) { + return; + } + + if (ReportUtils.isThread(report) && report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + Report.leaveRoom(report.reportID, false); + } + + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [isFocused]); + return ( Date: Mon, 25 Sep 2023 17:12:46 +0700 Subject: [PATCH 2/3] add comment --- src/libs/actions/Report.js | 19 ++++++++++--------- src/pages/home/ReportScreen.js | 2 +- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/Report.js b/src/libs/actions/Report.js index c260fb07ef6f8..8d078389e0b0d 100644 --- a/src/libs/actions/Report.js +++ b/src/libs/actions/Report.js @@ -1887,16 +1887,17 @@ function leaveRoom(reportID, shouldNavigate = true) { }, ); Navigation.dismissModal(); - if (shouldNavigate) { - if (Navigation.getTopmostReportId() === reportID) { - Navigation.goBack(ROUTES.HOME); - } - if (report.parentReportID) { - Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.parentReportID), CONST.NAVIGATION.TYPE.FORCED_UP); - return; - } - navigateToConciergeChat(); + if (!shouldNavigate) { + return; } + if (Navigation.getTopmostReportId() === reportID) { + Navigation.goBack(ROUTES.HOME); + } + if (report.parentReportID) { + Navigation.navigate(ROUTES.REPORT_WITH_ID.getRoute(report.parentReportID), CONST.NAVIGATION.TYPE.FORCED_UP); + return; + } + navigateToConciergeChat(); } /** diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 1b2f0b79efa40..2f4ec76543763 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -355,7 +355,7 @@ function ReportScreen({ if (isFocused) { return; } - + // When the report screen is unmounted or no longer in focus, and the user has no comments on that thread, call LeaveRoom if (ReportUtils.isThread(report) && report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { Report.leaveRoom(report.reportID, false); } From 6269ba7f6eb594fcd6cc633e2f72208eb91b1bdf Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Tue, 26 Sep 2023 11:05:56 +0700 Subject: [PATCH 3/3] add dependencies to useEffect --- src/pages/home/ReportScreen.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 2f4ec76543763..7f62cdf333d1d 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -181,6 +181,8 @@ function ReportScreen({ const didSubscribeToReportLeavingEvents = useRef(false); const isDefaultReport = checkDefaultReport(report); + const isThread = ReportUtils.isThread(report); + const isNotificationPreferenceHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN; let headerView = ( { - if (isFocused) { + if (isFocused || !isThread || !isNotificationPreferenceHidden) { return; } - // When the report screen is unmounted or no longer in focus, and the user has no comments on that thread, call LeaveRoom - if (ReportUtils.isThread(report) && report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { - Report.leaveRoom(report.reportID, false); - } - - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [isFocused]); + Report.leaveRoom(reportID, false); + }, [isFocused, isThread, isNotificationPreferenceHidden, reportID]); return (