Skip to content

Commit 6725f3f

Browse files
authored
Merge pull request #94114 from marufsharifi/fix/preserve-search-context-when-leaving-thread
Preserve Search context when leaving a thread
2 parents 0d0e0d8 + bf2395b commit 6725f3f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

src/libs/actions/Report/index.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ import {
174174
import {buildOptimisticSnapshotData, getCurrentSearchQueryJSON} from '@libs/SearchQueryUtils';
175175
import playSound, {SOUNDS} from '@libs/Sound';
176176
import {getAmount, getCurrency, getNegatedAmountTransaction, isOnHold, recalculateUnreportedTransactionDetails, shouldClearConvertedAmount} from '@libs/TransactionUtils';
177+
import {getSearchParamFromPath} from '@libs/Url';
177178
import {buildSecureDownloadURL} from '@libs/UrlUtils';
178179
import Visibility from '@libs/Visibility';
179180
import {cacheAttachment, removeCachedAttachment} from '@userActions/Attachment';
@@ -201,6 +202,7 @@ import type {OnboardingAccounting} from '@src/CONST';
201202
import CONST from '@src/CONST';
202203
import ONYXKEYS from '@src/ONYXKEYS';
203204
import ROUTES, {DYNAMIC_ROUTES} from '@src/ROUTES';
205+
import type {Route} from '@src/ROUTES';
204206
import INPUT_IDS from '@src/types/form/NewRoomForm';
205207
import type {
206208
AnyRequest,
@@ -4701,6 +4703,21 @@ function navigateToMostRecentReport(
47014703
}
47024704
}
47034705

4706+
function getSearchThreadLeaveRoute(report: Report, activeRoute: string): Route | undefined {
4707+
if (!isSearchTopmostFullScreenRoute() || !isChatThreadReportUtils(report) || !report.parentReportID || !report.parentReportActionID) {
4708+
return undefined;
4709+
}
4710+
4711+
const parentBackTo = getSearchParamFromPath(activeRoute, 'backTo');
4712+
const nestedBackTo = parentBackTo ? getSearchParamFromPath(parentBackTo, 'backTo') : undefined;
4713+
4714+
return ROUTES.SEARCH_REPORT.getRoute({
4715+
reportID: report.parentReportID,
4716+
reportActionID: report.parentReportActionID,
4717+
backTo: nestedBackTo ?? parentBackTo ?? undefined,
4718+
});
4719+
}
4720+
47044721
function getMostRecentReportID(currentReport: OnyxEntry<Report>, conciergeReportID: string | undefined) {
47054722
const lastAccessedReportID = findLastAccessedReport(false, false, currentReport?.reportID)?.reportID;
47064723
return lastAccessedReportID ?? conciergeReportID;
@@ -4793,6 +4810,7 @@ function leaveRoom(
47934810
) {
47944811
const reportID = report.reportID;
47954812
const isChatThread = isChatThreadReportUtils(report);
4813+
const activeRoute = Navigation.getActiveRoute();
47964814

47974815
// Pusher's leavingStatus should be sent earlier.
47984816
// Place the broadcast before calling the LeaveRoom API to prevent a race condition
@@ -4887,6 +4905,12 @@ function leaveRoom(
48874905

48884906
API.write(WRITE_COMMANDS.LEAVE_ROOM, parameters, {optimisticData, successData, failureData});
48894907

4908+
const searchThreadLeaveRoute = getSearchThreadLeaveRoute(report, activeRoute);
4909+
if (searchThreadLeaveRoute) {
4910+
Navigation.goBack(searchThreadLeaveRoute, {compareParams: false});
4911+
return;
4912+
}
4913+
48904914
// If this is the leave action from a workspace room, simply dismiss the modal, i.e., allow the user to view the room and join again immediately.
48914915
// If this is the leave action from a chat thread (even if the chat thread is in a room), do not allow the user to stay in the thread after leaving.
48924916
if (isWorkspaceMemberLeavingWorkspaceRoom && !isChatThread) {

0 commit comments

Comments
 (0)