Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pronouns is empty when we access by deep link after signing in #28368

Merged
merged 4 commits into from
Oct 4, 2023
Merged
Changes from 3 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
71 changes: 50 additions & 21 deletions src/pages/settings/Profile/PronounsPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import _ from 'underscore';
import lodashGet from 'lodash/get';
import React, {useState, useMemo} from 'react';
import React, {useState, useMemo, useEffect} from 'react';
import {withOnyx} from 'react-native-onyx';
import PropTypes from 'prop-types';
import withCurrentUserPersonalDetails, {withCurrentUserPersonalDetailsPropTypes, withCurrentUserPersonalDetailsDefaultProps} from '../../../components/withCurrentUserPersonalDetails';
import ScreenWrapper from '../../../components/ScreenWrapper';
import HeaderWithBackButton from '../../../components/HeaderWithBackButton';
Expand All @@ -12,27 +14,41 @@ import ROUTES from '../../../ROUTES';
import Navigation from '../../../libs/Navigation/Navigation';
import SelectionList from '../../../components/SelectionList';
import useLocalize from '../../../hooks/useLocalize';
import ONYXKEYS from '../../../ONYXKEYS';
import FullScreenLoadingIndicator from '../../../components/FullscreenLoadingIndicator';
import compose from '../../../libs/compose';

const propTypes = {
...withCurrentUserPersonalDetailsPropTypes,

/** Indicates whether the app is loading initial data */
isLoadingApp: PropTypes.bool,
};

const defaultProps = {
...withCurrentUserPersonalDetailsDefaultProps,
isLoadingApp: true,
};

function PronounsPage({currentUserPersonalDetails}) {
function PronounsPage({currentUserPersonalDetails, isLoadingApp}) {
const {translate} = useLocalize();
const currentPronouns = lodashGet(currentUserPersonalDetails, 'pronouns', '');
const currentPronounsKey = currentPronouns.substring(CONST.PRONOUNS.PREFIX.length);
const [searchValue, setSearchValue] = useState('');

const [searchValue, setSearchValue] = useState(() => {
useEffect(() => {
if (isLoadingApp && _.isEmpty(currentUserPersonalDetails.login)) {
return;
}
const currentPronounsText = _.chain(CONST.PRONOUNS_LIST)
.find((_value) => _value === currentPronounsKey)
.value();

return currentPronounsText ? translate(`pronouns.${currentPronounsText}`) : '';
});
setSearchValue(currentPronounsText ? translate(`pronouns.${currentPronounsText}`) : '');

// Only need to add login to dependency because after the data is loaded, other fields are also exist
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentUserPersonalDetails.login, isLoadingApp]);

const filteredPronounsList = useMemo(() => {
const pronouns = _.chain(CONST.PRONOUNS_LIST)
Expand Down Expand Up @@ -69,21 +85,27 @@ function PronounsPage({currentUserPersonalDetails}) {
includeSafeAreaPaddingBottom={false}
testID={PronounsPage.displayName}
>
<HeaderWithBackButton
title={translate('pronounsPage.pronouns')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_PROFILE)}
/>
<Text style={[styles.ph5, styles.mb3]}>{translate('pronounsPage.isShownOnProfile')}</Text>
<SelectionList
headerMessage={headerMessage}
textInputLabel={translate('pronounsPage.pronouns')}
textInputPlaceholder={translate('pronounsPage.placeholderText')}
textInputValue={searchValue}
sections={[{data: filteredPronounsList, indexOffset: 0}]}
onSelectRow={updatePronouns}
onChangeText={setSearchValue}
initiallyFocusedOptionKey={currentPronounsKey}
/>
{isLoadingApp && _.isEmpty(currentUserPersonalDetails.login) ? (
<FullScreenLoadingIndicator />
) : (
<>
<HeaderWithBackButton
title={translate('pronounsPage.pronouns')}
onBackButtonPress={() => Navigation.goBack(ROUTES.SETTINGS_PROFILE)}
/>
<Text style={[styles.ph5, styles.mb3]}>{translate('pronounsPage.isShownOnProfile')}</Text>
<SelectionList
headerMessage={headerMessage}
textInputLabel={translate('pronounsPage.pronouns')}
textInputPlaceholder={translate('pronounsPage.placeholderText')}
textInputValue={searchValue}
sections={[{data: filteredPronounsList, indexOffset: 0}]}
onSelectRow={updatePronouns}
onChangeText={setSearchValue}
initiallyFocusedOptionKey={currentPronounsKey}
/>
</>
)}
</ScreenWrapper>
);
}
Expand All @@ -92,4 +114,11 @@ PronounsPage.propTypes = propTypes;
PronounsPage.defaultProps = defaultProps;
PronounsPage.displayName = 'PronounsPage';

export default withCurrentUserPersonalDetails(PronounsPage);
export default compose(
withCurrentUserPersonalDetails,
withOnyx({
isLoadingApp: {
key: ONYXKEYS.IS_LOADING_APP,
},
}),
)(PronounsPage);
Loading