-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix: Leave thread chat when has no comment #27849
Changes from 5 commits
08337c3
844752d
1555286
3a8f8f0
475a7e0
6269ba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'; | ||
|
@@ -153,6 +153,7 @@ function ReportScreen({ | |
const reactionListRef = useRef(); | ||
const prevReport = usePrevious(report); | ||
const prevUserLeavingStatus = usePrevious(userLeavingStatus); | ||
const isFocused = useIsFocused(); | ||
|
||
const [skeletonViewContainerHeight, setSkeletonViewContainerHeight] = useState(0); | ||
const [isBannerVisible, setIsBannerVisible] = useState(true); | ||
|
@@ -350,6 +351,18 @@ function ReportScreen({ | |
[report, isLoading, shouldHideReport, isDefaultReport, isOptimisticDelete, userLeavingStatus], | ||
); | ||
|
||
useEffect(() => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Will this hook runs when component unmounts ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it will |
||
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) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's add a comment explaining this hook. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should prefer early return here: if (!ReportUtils.isThread(report) || report.notificationPreference !== CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN) {
return;
}
Report.leaveRoom(report.reportID, false); |
||
Report.leaveRoom(report.reportID, false); | ||
} | ||
|
||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why didn’t we pass all deps , basically the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should trigger this useEffect once the report loses focus There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree we don't want to run this whenever any property on the report changes. However, I think we probably want to make sure that the correct report data is used and want to avoid suppressing the lint rule. So maybe we can workaround the lint rule with something like this: const isThread = ReportUtils.isThread(report);
const isNotificationPreferenceHidden = report.notificationPreference === CONST.REPORT.NOTIFICATION_PREFERENCE.HIDDEN;
const reportID = report.reportID;
// When the report screen is unmounted or no longer in focus, and the user has no comments on that thread, call LeaveRoom
useEffect(() => {
if (isFocused || !isThread || !isNotificationPreferenceHidden) {
return;
}
Report.leaveRoom(reportID, false);
}, [isFocused, isThread, isNotificationPreferenceHidden, reportID]); |
||
}, [isFocused]); | ||
|
||
return ( | ||
<ReportScreenContext.Provider | ||
value={{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move this line above the modal dismissal .
Bug: User is navigated to concierge after leaving the thread
CleanShot.2023-09-26.at.16.07.37.mp4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@fedirjh I see the problem, this PR changed the logic
so I don't think just moving that IF condition will work since when we call LeaveRoom, we set the optimistic data of that report statusNum to CLOSED
App/src/libs/actions/Report.js
Line 1868 in fff2dd4
In ReportScreen, we have a logic to navigate to Concierge once statusNum is CLOSED
App/src/pages/home/ReportScreen.js
Lines 312 to 321 in fff2dd4
Working on this to find a solution
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think one simple solution for this bug is that we add an optimistic prop let's say
shouldNavigate
and use it to prevent redirection insideReportScreen
.