From 2ccf2dc71673050c50cc9544859c7b444676dfc2 Mon Sep 17 00:00:00 2001 From: Miguel Alatzar Date: Thu, 2 Jul 2020 10:24:19 -0700 Subject: [PATCH] [MM-26077] Emoji autocomplete fixes (#4512) * Use 0 height over null and move fuse * Deconstruct props * Update app/components/autocomplete/emoji_suggestion/emoji_suggestion.js Co-authored-by: Elias Nahum * Update app/components/autocomplete/emoji_suggestion/emoji_suggestion.js * Update snapshot Co-authored-by: Elias Nahum --- .../emoji_suggestion.test.js.snap | 42 ++++++++++++++++++- .../emoji_suggestion/emoji_suggestion.js | 41 ++++++++++++++---- .../emoji_suggestion/emoji_suggestion.test.js | 11 ----- .../autocomplete/emoji_suggestion/index.js | 13 ------ 4 files changed, 73 insertions(+), 34 deletions(-) diff --git a/app/components/autocomplete/emoji_suggestion/__snapshots__/emoji_suggestion.test.js.snap b/app/components/autocomplete/emoji_suggestion/__snapshots__/emoji_suggestion.test.js.snap index 9d6be4bd6..f277ee24c 100644 --- a/app/components/autocomplete/emoji_suggestion/__snapshots__/emoji_suggestion.test.js.snap +++ b/app/components/autocomplete/emoji_suggestion/__snapshots__/emoji_suggestion.test.js.snap @@ -1,6 +1,45 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`components/autocomplete/emoji_suggestion should match snapshot 1`] = `null`; +exports[`components/autocomplete/emoji_suggestion should match snapshot 1`] = ` + +`; exports[`components/autocomplete/emoji_suggestion should match snapshot 2`] = ` { - const {emojis, fuse} = this.props; + const {emojis} = this.props; let sorter = compareEmojis; if (searchTerm.trim().length) { @@ -198,18 +216,23 @@ export default class EmojiSuggestion extends PureComponent { render() { const {maxListHeight, theme, nestedScrollEnabled} = this.props; + let height; if (!this.state.active) { - // If we are not in an active state return null so nothing is rendered - // other components are not blocked. - return null; + // If we are not in an active state set a height of 0 so nothing is rendered + // and other components are not blocked. + height = 0; + if (this.listRef.current) { + this.listRef.current.scrollToOffset({offset: 0}); + } } const style = getStyleFromTheme(theme); return ( { }, }; const emojis = selectEmojisByName(state); - const options = { - shouldSort: false, - threshold: 0.3, - location: 0, - distance: 10, - includeMatches: true, - findAllMatches: true, - }; - const fuse = new Fuse(emojis, options); const baseProps = { actions: { addReactionToLatestPost: jest.fn(), @@ -38,7 +28,6 @@ describe('components/autocomplete/emoji_suggestion', () => { cursorPosition: 0, customEmojisEnabled: false, emojis, - fuse, isSearch: false, theme: Preferences.THEMES.default, onChangeText: jest.fn(), diff --git a/app/components/autocomplete/emoji_suggestion/index.js b/app/components/autocomplete/emoji_suggestion/index.js index f490b3d3b..881ae4a8d 100644 --- a/app/components/autocomplete/emoji_suggestion/index.js +++ b/app/components/autocomplete/emoji_suggestion/index.js @@ -3,7 +3,6 @@ import {connect} from 'react-redux'; import {bindActionCreators} from 'redux'; -import Fuse from 'fuse.js'; import {addReactionToLatestPost} from '@actions/views/emoji'; import {autocompleteCustomEmojis} from '@mm-redux/actions/emojis'; @@ -15,20 +14,8 @@ import EmojiSuggestion from './emoji_suggestion'; function mapStateToProps(state) { const emojis = selectEmojisByName(state); - const options = { - shouldSort: false, - threshold: 0.3, - location: 0, - distance: 10, - includeMatches: true, - findAllMatches: true, - }; - - const list = emojis.length ? emojis : []; - const fuse = new Fuse(list, options); return { - fuse, emojis, customEmojisEnabled: getConfig(state).EnableCustomEmoji === 'true', theme: getTheme(state),