* Remove mattermost-redux * Move mm-redux files into app/redux * Add @redux path to tsconfig.json * Fix imports * Install missing dependencies * Fix tsc errors * Fix i18n_utils test * Fix more imports * Remove redux websocket * Fix tests * Rename @redux * Apply changes from mattermost-redux PR 1103 * Remove mattermost-redux mention in template * Add missing imports * Rename app/redux/ to app/mm-redux/ * Remove test file * Fix fetching Sidebar GM profiles Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
60 lines
1.6 KiB
JavaScript
60 lines
1.6 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 '@mm-redux/selectors/entities/emojis';
|
|
import {autocompleteCustomEmojis} from '@mm-redux/actions/emojis';
|
|
|
|
import {addReactionToLatestPost} from 'app/actions/views/emoji';
|
|
import {getTheme} from '@mm-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),
|
|
};
|
|
}
|
|
|
|
function mapDispatchToProps(dispatch) {
|
|
return {
|
|
actions: bindActionCreators({
|
|
addReactionToLatestPost,
|
|
autocompleteCustomEmojis,
|
|
}, dispatch),
|
|
};
|
|
}
|
|
|
|
export default connect(mapStateToProps, mapDispatchToProps)(EmojiSuggestion);
|