Skip to content

Commit

Permalink
Merge pull request #51105 from Krishna2323/krishna2323/issue/50021
Browse files Browse the repository at this point in the history
fix: Search - Selection persists after the expense is deleted and no expense is selected.
  • Loading branch information
MarioExpensify authored Oct 22, 2024
2 parents d059ac1 + 71c6a5c commit 3e27050
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/components/Search/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {useNavigation} from '@react-navigation/native';
import {useIsFocused, useNavigation} from '@react-navigation/native';
import type {StackNavigationProp} from '@react-navigation/stack';
import React, {useCallback, useEffect, useRef, useState} from 'react';
import {View} from 'react-native';
Expand All @@ -21,6 +21,7 @@ import * as SearchActions from '@libs/actions/Search';
import * as DeviceCapabilities from '@libs/DeviceCapabilities';
import Log from '@libs/Log';
import memoize from '@libs/memoize';
import isSearchTopmostCentralPane from '@libs/Navigation/isSearchTopmostCentralPane';
import * as ReportUtils from '@libs/ReportUtils';
import * as SearchUtils from '@libs/SearchUtils';
import Navigation from '@navigation/Navigation';
Expand Down Expand Up @@ -92,6 +93,7 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
const {isSmallScreenWidth, isLargeScreenWidth} = useResponsiveLayout();
const navigation = useNavigation<StackNavigationProp<AuthScreensParamList>>();
const isFocused = useIsFocused();
const lastSearchResultsRef = useRef<OnyxEntry<SearchResults>>();
const {setCurrentSearchHash, setSelectedTransactions, selectedTransactions, clearSelectedTransactions, setShouldShowStatusBarLoading, lastSearchType, setLastSearchType} =
useSearchContext();
Expand Down Expand Up @@ -248,6 +250,17 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
turnOffMobileSelectionMode();
}, [isSearchResultsEmpty, prevIsSearchResultEmpty]);

useEffect(
() => () => {
if (isSearchTopmostCentralPane()) {
return;
}
clearSelectedTransactions();
turnOffMobileSelectionMode();
},
[isFocused, clearSelectedTransactions],
);

if (shouldShowLoadingState) {
return (
<SearchRowSkeleton
Expand Down

0 comments on commit 3e27050

Please sign in to comment.