Skip to content

Commit

Permalink
fix: Search - Selection persists after the expense is deleted and no …
Browse files Browse the repository at this point in the history
…expense is selected.

Signed-off-by: krishna2323 <[email protected]>
  • Loading branch information
Krishna2323 committed Oct 18, 2024
1 parent 41ed362 commit 71c6a5c
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 @@ -90,6 +91,7 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr
const styles = useThemeStyles();
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 @@ -246,6 +248,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 71c6a5c

Please sign in to comment.