-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, useRef, 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'; | ||
|
@@ -12,27 +14,43 @@ 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 */ | ||
isLoadingReportData: PropTypes.bool, | ||
}; | ||
|
||
const defaultProps = { | ||
...withCurrentUserPersonalDetailsDefaultProps, | ||
isLoadingReportData: true, | ||
}; | ||
|
||
function PronounsPage({currentUserPersonalDetails}) { | ||
function PronounsPage({currentUserPersonalDetails, isLoadingReportData}) { | ||
const {translate} = useLocalize(); | ||
const currentPronouns = lodashGet(currentUserPersonalDetails, 'pronouns', ''); | ||
const currentPronounsKey = currentPronouns.substring(CONST.PRONOUNS.PREFIX.length); | ||
const loadingCompleteRef = useRef(false); | ||
const [searchValue, setSearchValue] = useState(''); | ||
|
||
const [searchValue, setSearchValue] = useState(() => { | ||
useEffect(() => { | ||
if ((isLoadingReportData && _.isEmpty(currentUserPersonalDetails.login)) || loadingCompleteRef.current) { | ||
return; | ||
} | ||
loadingCompleteRef.current = true; | ||
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, isLoadingReportData]); | ||
|
||
const filteredPronounsList = useMemo(() => { | ||
const pronouns = _.chain(CONST.PRONOUNS_LIST) | ||
|
@@ -69,21 +87,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} | ||
/> | ||
{isLoadingReportData && _.isEmpty(currentUserPersonalDetails.login) ? ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we already have currentUserPersonalDetail, we don't need to wait |
||
<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> | ||
); | ||
} | ||
|
@@ -92,4 +116,11 @@ PronounsPage.propTypes = propTypes; | |
PronounsPage.defaultProps = defaultProps; | ||
PronounsPage.displayName = 'PronounsPage'; | ||
|
||
export default withCurrentUserPersonalDetails(PronounsPage); | ||
export default compose( | ||
withCurrentUserPersonalDetails, | ||
withOnyx({ | ||
isLoadingReportData: { | ||
key: ONYXKEYS.IS_LOADING_REPORT_DATA, | ||
}, | ||
}), | ||
)(PronounsPage); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dukenv0307 Can you please explain this condition? I'm not able to understand fully why we need to use the ref here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe the expectation here is only to set the current pronouns to the state the first time. After that, if we update this on another device, we don't want to update this to search text because we are finding another in the current device.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dukenv0307 I think if we use
IS_LOADING_APP
instead ofIS_LOADING_REPORT_DATA
, there would be no need for the ref. Can you please verify / confirm?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we are using
IS_LOADING_REPORT_DATA
from other components and only useIS_LOADING_APP
inAuthScreen
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, is this an issue? I mean, we can use it anywhere. Essentially, it is just setting the value of the constant as
true
whenopenApp
is called. The commandopenApp
is called only once on the first load and this is what we need here as well I assume.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's try it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it work fine? 😸
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested and it works fine.