Refactor initial state: auto_play_gif (#5576)

This commit is contained in:
Nolan Lawson 2017-10-31 14:58:07 -07:00 committed by Yamagishi Kazutoshi
parent 47d56438da
commit 60f962eedc
4 changed files with 8 additions and 15 deletions

View file

@ -157,7 +157,6 @@ class EmojiPickerMenu extends React.PureComponent {
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
skinTone: PropTypes.number.isRequired, skinTone: PropTypes.number.isRequired,
onSkinTone: PropTypes.func.isRequired, onSkinTone: PropTypes.func.isRequired,
autoPlay: PropTypes.bool,
}; };
static defaultProps = { static defaultProps = {
@ -235,7 +234,7 @@ class EmojiPickerMenu extends React.PureComponent {
} }
render () { render () {
const { loading, style, intl, custom_emojis, autoPlay, skinTone, frequentlyUsedEmojis } = this.props; const { loading, style, intl, custom_emojis, skinTone, frequentlyUsedEmojis } = this.props;
if (loading) { if (loading) {
return <div style={{ width: 299 }} />; return <div style={{ width: 299 }} />;
@ -250,7 +249,7 @@ class EmojiPickerMenu extends React.PureComponent {
perLine={8} perLine={8}
emojiSize={22} emojiSize={22}
sheetSize={32} sheetSize={32}
custom={buildCustomEmojis(custom_emojis, autoPlay)} custom={buildCustomEmojis(custom_emojis)}
color='' color=''
emoji='' emoji=''
set='twitter' set='twitter'
@ -284,7 +283,6 @@ export default class EmojiPickerDropdown extends React.PureComponent {
static propTypes = { static propTypes = {
custom_emojis: ImmutablePropTypes.list, custom_emojis: ImmutablePropTypes.list,
frequentlyUsedEmojis: PropTypes.arrayOf(PropTypes.string), frequentlyUsedEmojis: PropTypes.arrayOf(PropTypes.string),
autoPlay: PropTypes.bool,
intl: PropTypes.object.isRequired, intl: PropTypes.object.isRequired,
onPickEmoji: PropTypes.func.isRequired, onPickEmoji: PropTypes.func.isRequired,
onSkinTone: PropTypes.func.isRequired, onSkinTone: PropTypes.func.isRequired,
@ -346,7 +344,7 @@ export default class EmojiPickerDropdown extends React.PureComponent {
} }
render () { render () {
const { intl, onPickEmoji, autoPlay, onSkinTone, skinTone, frequentlyUsedEmojis } = this.props; const { intl, onPickEmoji, onSkinTone, skinTone, frequentlyUsedEmojis } = this.props;
const title = intl.formatMessage(messages.emoji); const title = intl.formatMessage(messages.emoji);
const { active, loading } = this.state; const { active, loading } = this.state;
@ -366,7 +364,6 @@ export default class EmojiPickerDropdown extends React.PureComponent {
loading={loading} loading={loading}
onClose={this.onHideDropdown} onClose={this.onHideDropdown}
onPick={onPickEmoji} onPick={onPickEmoji}
autoPlay={autoPlay}
onSkinTone={onSkinTone} onSkinTone={onSkinTone}
skinTone={skinTone} skinTone={skinTone}
frequentlyUsedEmojis={frequentlyUsedEmojis} frequentlyUsedEmojis={frequentlyUsedEmojis}

View file

@ -61,7 +61,6 @@ const getCustomEmojis = createSelector([
const mapStateToProps = state => ({ const mapStateToProps = state => ({
custom_emojis: getCustomEmojis(state), custom_emojis: getCustomEmojis(state),
autoPlay: state.getIn(['meta', 'auto_play_gif']),
skinTone: state.getIn(['settings', 'skinTone']), skinTone: state.getIn(['settings', 'skinTone']),
frequentlyUsedEmojis: getFrequentlyUsedEmojis(state), frequentlyUsedEmojis: getFrequentlyUsedEmojis(state),
}); });

View file

@ -1,3 +1,4 @@
import { autoPlayGif } from '../../initial_state';
import unicodeMapping from './emoji_unicode_mapping_light'; import unicodeMapping from './emoji_unicode_mapping_light';
import Trie from 'substring-trie'; import Trie from 'substring-trie';
@ -5,8 +6,6 @@ const trie = new Trie(Object.keys(unicodeMapping));
const assetHost = process.env.CDN_HOST || ''; const assetHost = process.env.CDN_HOST || '';
let allowAnimations = false;
const emojify = (str, customEmojis = {}) => { const emojify = (str, customEmojis = {}) => {
let rtn = ''; let rtn = '';
for (;;) { for (;;) {
@ -27,7 +26,7 @@ const emojify = (str, customEmojis = {}) => {
// now got a replacee as ':shortname:' // now got a replacee as ':shortname:'
// if you want additional emoji handler, add statements below which set replacement and return true. // if you want additional emoji handler, add statements below which set replacement and return true.
if (shortname in customEmojis) { if (shortname in customEmojis) {
const filename = allowAnimations ? customEmojis[shortname].url : customEmojis[shortname].static_url; const filename = autoPlayGif ? customEmojis[shortname].url : customEmojis[shortname].static_url;
replacement = `<img draggable="false" class="emojione" alt="${shortname}" title="${shortname}" src="${filename}" />`; replacement = `<img draggable="false" class="emojione" alt="${shortname}" title="${shortname}" src="${filename}" />`;
return true; return true;
} }
@ -51,14 +50,12 @@ const emojify = (str, customEmojis = {}) => {
export default emojify; export default emojify;
export const buildCustomEmojis = (customEmojis, overrideAllowAnimations = false) => { export const buildCustomEmojis = (customEmojis) => {
const emojis = []; const emojis = [];
allowAnimations = overrideAllowAnimations;
customEmojis.forEach(emoji => { customEmojis.forEach(emoji => {
const shortcode = emoji.get('shortcode'); const shortcode = emoji.get('shortcode');
const url = allowAnimations ? emoji.get('url') : emoji.get('static_url'); const url = autoPlayGif ? emoji.get('url') : emoji.get('static_url');
const name = shortcode.replace(':', ''); const name = shortcode.replace(':', '');
emojis.push({ emojis.push({

View file

@ -8,7 +8,7 @@ const initialState = ImmutableList();
export default function custom_emojis(state = initialState, action) { export default function custom_emojis(state = initialState, action) {
switch(action.type) { switch(action.type) {
case STORE_HYDRATE: case STORE_HYDRATE:
emojiSearch('', { custom: buildCustomEmojis(action.state.get('custom_emojis', []), action.state.getIn(['meta', 'auto_play_gif'], false)) }); emojiSearch('', { custom: buildCustomEmojis(action.state.get('custom_emojis', [])) });
return action.state.get('custom_emojis'); return action.state.get('custom_emojis');
default: default:
return state; return state;