Skip to content

Commit 56e35ce

Browse files
Merge pull request #54583 from Expensify/revert-53519-fix-49322
Revert "fix: when selecting categories, the selected categories get reset"
2 parents 5037479 + e9d5f82 commit 56e35ce

File tree

4 files changed

+27
-49
lines changed

4 files changed

+27
-49
lines changed

src/hooks/useCleanupSelectedOptions/index.ts

-21
This file was deleted.

src/pages/workspace/categories/WorkspaceCategoriesPage.tsx

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import {useFocusEffect} from '@react-navigation/native';
1+
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
22
import lodashSortBy from 'lodash/sortBy';
33
import React, {useCallback, useEffect, useMemo, useState} from 'react';
44
import {ActivityIndicator, View} from 'react-native';
@@ -23,7 +23,6 @@ import TableListItemSkeleton from '@components/Skeletons/TableRowSkeleton';
2323
import Text from '@components/Text';
2424
import TextLink from '@components/TextLink';
2525
import useAutoTurnSelectionModeOffWhenHasNoActiveOption from '@hooks/useAutoTurnSelectionModeOffWhenHasNoActiveOption';
26-
import useCleanupSelectedOptions from '@hooks/useCleanupSelectedOptions';
2726
import useEnvironment from '@hooks/useEnvironment';
2827
import useLocalize from '@hooks/useLocalize';
2928
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
@@ -71,6 +70,7 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
7170
const [selectedCategories, setSelectedCategories] = useState<Record<string, boolean>>({});
7271
const [isDownloadFailureModalVisible, setIsDownloadFailureModalVisible] = useState(false);
7372
const [deleteCategoriesConfirmModalVisible, setDeleteCategoriesConfirmModalVisible] = useState(false);
73+
const isFocused = useIsFocused();
7474
const {environmentURL} = useEnvironment();
7575
const policyId = route.params.policyID ?? '-1';
7676
const backTo = route.params?.backTo;
@@ -98,8 +98,12 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
9898
}, [fetchCategories]),
9999
);
100100

101-
const cleanupSelectedOption = useCallback(() => setSelectedCategories({}), []);
102-
useCleanupSelectedOptions(cleanupSelectedOption);
101+
useEffect(() => {
102+
if (isFocused) {
103+
return;
104+
}
105+
setSelectedCategories({});
106+
}, [isFocused]);
103107

104108
const categoryList = useMemo<PolicyOption[]>(
105109
() =>
@@ -147,10 +151,6 @@ function WorkspaceCategoriesPage({route}: WorkspaceCategoriesPageProps) {
147151
};
148152

149153
const navigateToCategorySettings = (category: PolicyOption) => {
150-
if (isSmallScreenWidth && selectionMode?.isEnabled) {
151-
toggleCategory(category);
152-
return;
153-
}
154154
Navigation.navigate(
155155
isQuickSettingsFlow
156156
? ROUTES.SETTINGS_CATEGORY_SETTINGS.getRoute(policyId, category.keyForList, backTo)

src/pages/workspace/tags/WorkspaceTagsPage.tsx

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import {useFocusEffect} from '@react-navigation/native';
1+
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
22
import lodashSortBy from 'lodash/sortBy';
3-
import React, {useCallback, useMemo, useState} from 'react';
3+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
44
import {ActivityIndicator, View} from 'react-native';
55
import {useOnyx} from 'react-native-onyx';
66
import Button from '@components/Button';
@@ -22,7 +22,6 @@ import CustomListHeader from '@components/SelectionListWithModal/CustomListHeade
2222
import TableListItemSkeleton from '@components/Skeletons/TableRowSkeleton';
2323
import Text from '@components/Text';
2424
import TextLink from '@components/TextLink';
25-
import useCleanupSelectedOptions from '@hooks/useCleanupSelectedOptions';
2625
import useEnvironment from '@hooks/useEnvironment';
2726
import useLocalize from '@hooks/useLocalize';
2827
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
@@ -65,6 +64,7 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
6564
const [isDownloadFailureModalVisible, setIsDownloadFailureModalVisible] = useState(false);
6665
const [isDeleteTagsConfirmModalVisible, setIsDeleteTagsConfirmModalVisible] = useState(false);
6766
const [isOfflineModalVisible, setIsOfflineModalVisible] = useState(false);
67+
const isFocused = useIsFocused();
6868
const policyID = route.params.policyID ?? '-1';
6969
const backTo = route.params.backTo;
7070
const policy = usePolicy(policyID);
@@ -87,8 +87,12 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
8787

8888
useFocusEffect(fetchTags);
8989

90-
const cleanupSelectedOption = useCallback(() => setSelectedTags({}), []);
91-
useCleanupSelectedOptions(cleanupSelectedOption);
90+
useEffect(() => {
91+
if (isFocused) {
92+
return;
93+
}
94+
setSelectedTags({});
95+
}, [isFocused]);
9296

9397
const getPendingAction = (policyTagList: PolicyTagList): PendingAction | undefined => {
9498
if (!policyTagList) {
@@ -172,10 +176,6 @@ function WorkspaceTagsPage({route}: WorkspaceTagsPageProps) {
172176
};
173177

174178
const navigateToTagSettings = (tag: TagListItem) => {
175-
if (isSmallScreenWidth && selectionMode?.isEnabled) {
176-
toggleTag(tag);
177-
return;
178-
}
179179
if (tag.orderWeight !== undefined) {
180180
Navigation.navigate(
181181
isQuickSettingsFlow ? ROUTES.SETTINGS_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight, backTo) : ROUTES.WORKSPACE_TAG_LIST_VIEW.getRoute(policyID, tag.orderWeight),

src/pages/workspace/taxes/WorkspaceTaxesPage.tsx

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import {useFocusEffect} from '@react-navigation/native';
2-
import React, {useCallback, useMemo, useState} from 'react';
1+
import {useFocusEffect, useIsFocused} from '@react-navigation/native';
2+
import React, {useCallback, useEffect, useMemo, useState} from 'react';
33
import {ActivityIndicator, View} from 'react-native';
44
import {useOnyx} from 'react-native-onyx';
55
import Button from '@components/Button';
@@ -17,7 +17,6 @@ import SelectionListWithModal from '@components/SelectionListWithModal';
1717
import CustomListHeader from '@components/SelectionListWithModal/CustomListHeader';
1818
import Text from '@components/Text';
1919
import TextLink from '@components/TextLink';
20-
import useCleanupSelectedOptions from '@hooks/useCleanupSelectedOptions';
2120
import useEnvironment from '@hooks/useEnvironment';
2221
import useLocalize from '@hooks/useLocalize';
2322
import useMobileSelectionMode from '@hooks/useMobileSelectionMode';
@@ -52,8 +51,7 @@ function WorkspaceTaxesPage({
5251
params: {policyID},
5352
},
5453
}: WorkspaceTaxesPageProps) {
55-
// eslint-disable-next-line rulesdir/prefer-shouldUseNarrowLayout-instead-of-isSmallScreenWidth
56-
const {shouldUseNarrowLayout, isSmallScreenWidth} = useResponsiveLayout();
54+
const {shouldUseNarrowLayout} = useResponsiveLayout();
5755
const styles = useThemeStyles();
5856
const theme = useTheme();
5957
const {translate} = useLocalize();
@@ -63,6 +61,7 @@ function WorkspaceTaxesPage({
6361
const {selectionMode} = useMobileSelectionMode();
6462
const defaultExternalID = policy?.taxRates?.defaultExternalID;
6563
const foreignTaxDefault = policy?.taxRates?.foreignTaxDefault;
64+
const isFocused = useIsFocused();
6665
const hasAccountingConnections = PolicyUtils.hasAccountingConnections(policy);
6766
const [connectionSyncProgress] = useOnyx(`${ONYXKEYS.COLLECTION.POLICY_CONNECTION_SYNC_PROGRESS}${policy?.id}`);
6867
const isSyncInProgress = isConnectionInProgress(connectionSyncProgress, policy);
@@ -87,8 +86,12 @@ function WorkspaceTaxesPage({
8786
}, [fetchTaxes]),
8887
);
8988

90-
const cleanupSelectedOption = useCallback(() => setSelectedTaxesIDs([]), []);
91-
useCleanupSelectedOptions(cleanupSelectedOption);
89+
useEffect(() => {
90+
if (isFocused) {
91+
return;
92+
}
93+
setSelectedTaxesIDs([]);
94+
}, [isFocused]);
9295

9396
const textForDefault = useCallback(
9497
(taxID: string, taxRate: TaxRate): string => {
@@ -189,10 +192,6 @@ function WorkspaceTaxesPage({
189192
if (!taxRate.keyForList) {
190193
return;
191194
}
192-
if (isSmallScreenWidth && selectionMode?.isEnabled) {
193-
toggleTax(taxRate);
194-
return;
195-
}
196195
Navigation.navigate(ROUTES.WORKSPACE_TAX_EDIT.getRoute(policyID, taxRate.keyForList));
197196
};
198197

0 commit comments

Comments
 (0)