From 25723729eb0417f6213fa34bf5ed17649978f5ee Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 11 Mar 2024 12:04:22 +0700 Subject: [PATCH 1/5] fix: re-join thread after leaving thread and returning with back button --- src/pages/home/ReportScreen.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index 2e19a2c6a940..e6774697fb24 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -405,6 +405,15 @@ function ReportScreen({ // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + useEffect(() => { + if (!isFocused || !ReportUtils.isChatThread(report) || report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + return; + } + + Report.openReport(report.reportID); + }, [isFocused, report]); + + useEffect(() => { // We don't want this effect to run on the first render. if (firstRenderRef.current) { From e9e02958d04e0f752ece6608b2de10a65620c9da Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Mon, 11 Mar 2024 12:21:41 +0700 Subject: [PATCH 2/5] fix lint --- src/pages/home/ReportScreen.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pages/home/ReportScreen.js b/src/pages/home/ReportScreen.js index e6774697fb24..ebfad2b13245 100644 --- a/src/pages/home/ReportScreen.js +++ b/src/pages/home/ReportScreen.js @@ -409,10 +409,9 @@ function ReportScreen({ if (!isFocused || !ReportUtils.isChatThread(report) || report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { return; } - + Report.openReport(report.reportID); }, [isFocused, report]); - useEffect(() => { // We don't want this effect to run on the first render. From fc2de787c6655bba1f80e85a41249053ed4f32cf Mon Sep 17 00:00:00 2001 From: dukenv0307 Date: Thu, 14 Mar 2024 17:13:48 +0700 Subject: [PATCH 3/5] Add comment useEffect in ReportScreen --- src/pages/home/ReportScreen.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 20d61133667e..c7575df0323a 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -123,7 +123,7 @@ function ReportScreen({ const {translate} = useLocalize(); const {isSmallScreenWidth} = useWindowDimensions(); const isFocused = useIsFocused(); - + const prevIsFocused = usePrevious(isFocused); const firstRenderRef = useRef(true); const flatListRef = useRef(null); const reactionListRef = useRef(null); @@ -362,13 +362,15 @@ function ReportScreen({ // eslint-disable-next-line react-hooks/exhaustive-deps }, []); + // Open report when the user has left the thread and go back with back button useEffect(() => { - if (!isFocused || !ReportUtils.isChatThread(report) || report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { + if (!isFocused || prevIsFocused || !ReportUtils.isChatThread(report) || report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { return; } - Report.openReport(report.reportID); - }, [isFocused, report]); + // I'm disabling the warning because we don't want run this useEffect when report is changed + // eslint-disable-next-line react-hooks/exhaustive-deps + }, [prevIsFocused, report.notificationPreference, isFocused]); useEffect(() => { // We don't want this effect to run on the first render. From f5189534a9fcd977a60f56d2e51ecee3452bfce9 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:43:51 +0700 Subject: [PATCH 4/5] Update comment ReportSceen Co-authored-by: Joel Davies --- src/pages/home/ReportScreen.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index c7575df0323a..88c52f56a88b 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -362,7 +362,7 @@ function ReportScreen({ // eslint-disable-next-line react-hooks/exhaustive-deps }, []); - // Open report when the user has left the thread and go back with back button + // If a user has chosen to leave a thread, and then returns to it (e.g. with the back button), we need to call `openReport` again in order to allow the user to rejoin and to receive real-time updates useEffect(() => { if (!isFocused || prevIsFocused || !ReportUtils.isChatThread(report) || report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) { return; From d78c0f15ab04c0cc4d698720c980194e7648a661 Mon Sep 17 00:00:00 2001 From: dukenv0307 <129500732+dukenv0307@users.noreply.github.com> Date: Thu, 14 Mar 2024 17:44:02 +0700 Subject: [PATCH 5/5] Update comment ReportSceen Co-authored-by: Joel Davies --- src/pages/home/ReportScreen.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/pages/home/ReportScreen.tsx b/src/pages/home/ReportScreen.tsx index 88c52f56a88b..4e12c75248d3 100644 --- a/src/pages/home/ReportScreen.tsx +++ b/src/pages/home/ReportScreen.tsx @@ -368,7 +368,8 @@ function ReportScreen({ return; } Report.openReport(report.reportID); - // I'm disabling the warning because we don't want run this useEffect when report is changed + + // We don't want to run this useEffect every time `report` is changed // eslint-disable-next-line react-hooks/exhaustive-deps }, [prevIsFocused, report.notificationPreference, isFocused]);