-
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
Update frequently used emojis in state whenever its onyx key changes #23965
Changes from all commits
04ab9fc
cac3ed3
4e61c76
ac20ac9
a026502
08017f7
d2f71e2
079e5bf
4d7800b
5949859
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import React, {useState, useMemo} from 'react'; | ||
import React, {useState, useMemo, useEffect} from 'react'; | ||
import {View} from 'react-native'; | ||
import {withOnyx} from 'react-native-onyx'; | ||
import PropTypes from 'prop-types'; | ||
|
@@ -27,23 +27,37 @@ const propTypes = { | |
/** Stores user's preferred skin tone */ | ||
preferredSkinTone: PropTypes.oneOfType([PropTypes.number, PropTypes.string]), | ||
|
||
/** Stores user's frequently used emojis */ | ||
// eslint-disable-next-line react/forbid-prop-types | ||
frequentlyUsedEmojis: PropTypes.arrayOf(PropTypes.object), | ||
|
||
/** Props related to translation */ | ||
...withLocalizePropTypes, | ||
}; | ||
|
||
const defaultProps = { | ||
preferredSkinTone: CONST.EMOJI_DEFAULT_SKIN_TONE, | ||
frequentlyUsedEmojis: [], | ||
}; | ||
|
||
function EmojiPickerMenu({preferredLocale, onEmojiSelected, preferredSkinTone, translate}) { | ||
function EmojiPickerMenu({preferredLocale, onEmojiSelected, preferredSkinTone, translate, frequentlyUsedEmojis}) { | ||
const emojiList = useAnimatedRef(); | ||
const allEmojis = useMemo(() => EmojiUtils.mergeEmojisWithFrequentlyUsedEmojis(emojis), []); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
const allEmojis = useMemo(() => EmojiUtils.mergeEmojisWithFrequentlyUsedEmojis(emojis), [frequentlyUsedEmojis]); | ||
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. Could you explain to me why we need this? I'd just like to understand. 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. We are calculating The 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. Got it! Thanks for the explanation. |
||
const headerEmojis = useMemo(() => EmojiUtils.getHeaderEmojis(allEmojis), [allEmojis]); | ||
const headerRowIndices = useMemo(() => _.map(headerEmojis, (headerEmoji) => Math.floor(headerEmoji.index / CONST.EMOJI_NUM_PER_ROW)), [headerEmojis]); | ||
const [filteredEmojis, setFilteredEmojis] = useState(allEmojis); | ||
const [headerIndices, setHeaderIndices] = useState(headerRowIndices); | ||
const {windowWidth} = useWindowDimensions(); | ||
|
||
useEffect(() => { | ||
setFilteredEmojis(allEmojis); | ||
}, [allEmojis]); | ||
|
||
useEffect(() => { | ||
setHeaderIndices(headerRowIndices); | ||
}, [headerRowIndices]); | ||
|
||
const getItemLayout = (data, index) => ({length: CONST.EMOJI_PICKER_ITEM_HEIGHT, offset: CONST.EMOJI_PICKER_ITEM_HEIGHT * index, index}); | ||
|
||
/** | ||
|
@@ -200,6 +214,9 @@ export default compose( | |
preferredSkinTone: { | ||
key: ONYXKEYS.PREFERRED_EMOJI_SKIN_TONE, | ||
}, | ||
frequentlyUsedEmojis: { | ||
key: ONYXKEYS.FREQUENTLY_USED_EMOJIS, | ||
}, | ||
}), | ||
)( | ||
React.forwardRef((props, ref) => ( | ||
|
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.
Did you delete this assignment entirely? I see you are calculating it inside
ComponentDidUpdate
but there is no assignment tothis.headerEmojis
there. I see it's used in CategoryShortcutBar, and because of that it's not visible nowThere 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.
after:
before:
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.
My bad, this is a mistake. Fixing 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.
I fixed it here, @robertKozik. Sry i missed this and thanks for the spot