Skip to content

Commit

Permalink
fix search term is lost
Browse files Browse the repository at this point in the history
  • Loading branch information
DylanDylann committed Dec 6, 2023
1 parent 1116f0f commit eb9c843
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
5 changes: 5 additions & 0 deletions src/pages/workspace/SearchInputManager.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// eslint-disable-next-line prefer-const
let searchInput = '';
export default {
searchInput,
};
15 changes: 14 additions & 1 deletion src/pages/workspace/WorkspaceInvitePage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import * as Policy from '@userActions/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SearchInputManager from './SearchInputManager';
import {policyDefaultProps, policyPropTypes} from './withPolicy';
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading';

Expand Down Expand Up @@ -75,6 +76,15 @@ function WorkspaceInvitePage(props) {
Policy.openWorkspaceInvitePage(props.route.params.policyID, _.keys(policyMemberEmailsToAccountIDs));
};

useEffect(() => {
if (!SearchInputManager.searchInput) {
return;
}
if (SearchInputManager.searchInput) {
setSearchTerm(SearchInputManager.searchInput);
}
}, []);

useEffect(() => {
Policy.clearErrors(props.route.params.policyID);
openWorkspaceInvitePage();
Expand Down Expand Up @@ -255,7 +265,10 @@ function WorkspaceInvitePage(props) {
sections={sections}
textInputLabel={translate('optionsSelector.nameEmailOrPhoneNumber')}
textInputValue={searchTerm}
onChangeText={setSearchTerm}
onChangeText={(value) => {
SearchInputManager.searchInput = value;
setSearchTerm(value);
}}
headerMessage={headerMessage}
onSelectRow={toggleOption}
onConfirm={inviteUser}
Expand Down
20 changes: 19 additions & 1 deletion src/pages/workspace/WorkspaceMembersPage.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import {useIsFocused} from '@react-navigation/native';
import lodashGet from 'lodash/get';
import PropTypes from 'prop-types';
import React, {useCallback, useEffect, useMemo, useRef, useState} from 'react';
Expand Down Expand Up @@ -32,6 +33,7 @@ import * as Policy from '@userActions/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import SearchInputManager from './SearchInputManager';
import {policyDefaultProps, policyPropTypes} from './withPolicy';
import withPolicyAndFullscreenLoading from './withPolicyAndFullscreenLoading';

Expand Down Expand Up @@ -85,6 +87,19 @@ function WorkspaceMembersPage(props) {
const isOfflineAndNoMemberDataAvailable = _.isEmpty(props.policyMembers) && props.network.isOffline;
const prevPersonalDetails = usePrevious(props.personalDetails);

const isFocusedScreen = useIsFocused();

useEffect(() => {
if (!SearchInputManager.searchInput) {
return;
}
if (SearchInputManager.searchInput) {
setSearchValue(SearchInputManager.searchInput);
}
}, [isFocusedScreen]);

useEffect(() => () => (SearchInputManager.searchInput = ''), []);

/**
* Get filtered personalDetails list with current policyMembers
* @param {Object} policyMembers
Expand Down Expand Up @@ -466,7 +481,10 @@ function WorkspaceMembersPage(props) {
sections={[{data, indexOffset: 0, isDisabled: false}]}
textInputLabel={props.translate('optionsSelector.findMember')}
textInputValue={searchValue}
onChangeText={setSearchValue}
onChangeText={(value) => {
SearchInputManager.searchInput = value;
setSearchValue(value);
}}
headerMessage={getHeaderMessage()}
headerContent={getHeaderContent()}
onSelectRow={(item) => toggleUser(item.accountID)}
Expand Down

0 comments on commit eb9c843

Please sign in to comment.