mattermost-mobile/app/components/autocomplete/emoji_suggestion/index.js
Jesús Espino 280577dbc7 MM-11725: Using the new server endpoint to autocomplete channels (#2100)
* MM-11725: Using the new server endpoint to autocomplete channels

* Fixing suggestions from the PR

* Updating mattermost-redux dependency

* Removing unnecesary Client4.getServerVersion usage
2018-09-14 15:06:11 -04:00

61 lines
1.7 KiB
JavaScript

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {connect} from 'react-redux';
import {createSelector} from 'reselect';
import {bindActionCreators} from 'redux';
import {getCustomEmojisByName} from 'mattermost-redux/selectors/entities/emojis';
import {autocompleteCustomEmojis} from 'mattermost-redux/actions/emojis';
import {addReactionToLatestPost} from 'app/actions/views/emoji';
import {getTheme} from 'mattermost-redux/selectors/entities/preferences';
import {EmojiIndicesByAlias} from 'app/utils/emojis';
import EmojiSuggestion from './emoji_suggestion';
import Fuse from 'fuse.js';
const getEmojisByName = createSelector(
getCustomEmojisByName,
(customEmojis) => {
const emoticons = new Set();
for (const [key] of [...EmojiIndicesByAlias.entries(), ...customEmojis.entries()]) {
emoticons.add(key);
}
return Array.from(emoticons);
}
);
function mapStateToProps(state) {
const options = {
shouldSort: true,
threshold: 0.3,
location: 0,
distance: 100,
minMatchCharLength: 2,
maxPatternLength: 32,
};
const emojis = getEmojisByName(state);
const list = emojis.length ? emojis : [];
const fuse = new Fuse(list, options);
return {
fuse,
emojis,
theme: getTheme(state),
serverVersion: state.entities.general.serverVersion,
};
}
function mapDispatchToProps(dispatch) {
return {
actions: bindActionCreators({
addReactionToLatestPost,
autocompleteCustomEmojis,
}, dispatch),
};
}
export default connect(mapStateToProps, mapDispatchToProps)(EmojiSuggestion);