Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 26 additions & 8 deletions src/components/Search/SearchContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {isTransactionCardGroupListItemType, isTransactionListItemType, isTransac
import CONST from '@src/CONST';
import type ChildrenProps from '@src/types/utils/ChildrenProps';
import {isEmptyObject} from '@src/types/utils/EmptyObject';
import type {SearchContext, SearchContextData} from './types';
import type {SearchContext, SearchContextData, SelectedTransactions} from './types';

const defaultSearchContextData: SearchContextData = {
currentSearchHash: -1,
Expand Down Expand Up @@ -137,16 +137,34 @@ function SearchContextProvider({children}: ChildrenProps) {

const removeTransaction: SearchContext['removeTransaction'] = useCallback(
(transactionID) => {
const selectedTransactionIDs = searchContextData.selectedTransactionIDs;
if (!transactionID || !selectedTransactionIDs.length) {
if (!transactionID) {
return;
}
setSearchContextData((prevState) => ({
...prevState,
selectedTransactionIDs: selectedTransactionIDs.filter((ID) => transactionID !== ID),
}));
const selectedTransactionIDs = searchContextData.selectedTransactionIDs;

if (!isEmptyObject(searchContextData.selectedTransactions)) {
const newSelectedTransactions = Object.entries(searchContextData.selectedTransactions).reduce((acc, [key, value]) => {
if (key === transactionID) {
return acc;
}
acc[key] = value;
return acc;
}, {} as SelectedTransactions);

setSearchContextData((prevState) => ({
...prevState,
selectedTransactions: newSelectedTransactions,
}));
}

if (selectedTransactionIDs.length > 0) {
setSearchContextData((prevState) => ({
...prevState,
selectedTransactionIDs: selectedTransactionIDs.filter((ID) => transactionID !== ID),
}));
}
},
[searchContextData.selectedTransactionIDs],
[searchContextData.selectedTransactionIDs, searchContextData.selectedTransactions],
);

const searchContext = useMemo<SearchContext>(
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/tags/WorkspaceTagsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
};

const navigateToTagSettings = (tag: TagListItem) => {
if (isSmallScreenWidth && !isMobileSelectionModeEnabled) {
if (isSmallScreenWidth && isMobileSelectionModeEnabled) {
toggleTag(tag);
return;
}
Expand Down
Loading