From 71c6a5c7f560fdbc2dd570c40585585e85b280f4 Mon Sep 17 00:00:00 2001 From: krishna2323 Date: Fri, 18 Oct 2024 23:58:22 +0530 Subject: [PATCH] fix: Search - Selection persists after the expense is deleted and no expense is selected. Signed-off-by: krishna2323 --- src/components/Search/index.tsx | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/Search/index.tsx b/src/components/Search/index.tsx index 0b0d91051bd2..effb29b50e23 100644 --- a/src/components/Search/index.tsx +++ b/src/components/Search/index.tsx @@ -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'; @@ -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'; @@ -90,6 +91,7 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr const styles = useThemeStyles(); const {isSmallScreenWidth, isLargeScreenWidth} = useResponsiveLayout(); const navigation = useNavigation>(); + const isFocused = useIsFocused(); const lastSearchResultsRef = useRef>(); const {setCurrentSearchHash, setSelectedTransactions, selectedTransactions, clearSelectedTransactions, setShouldShowStatusBarLoading, lastSearchType, setLastSearchType} = useSearchContext(); @@ -246,6 +248,17 @@ function Search({queryJSON, onSearchListScroll, contentContainerStyle}: SearchPr turnOffMobileSelectionMode(); }, [isSearchResultsEmpty, prevIsSearchResultEmpty]); + useEffect( + () => () => { + if (isSearchTopmostCentralPane()) { + return; + } + clearSelectedTransactions(); + turnOffMobileSelectionMode(); + }, + [isFocused, clearSelectedTransactions], + ); + if (shouldShowLoadingState) { return (