Made reactions re-render when custom emojis change (#5545)

Этот коммит содержится в:
Harrison Healey
2017-02-27 11:10:02 -05:00
коммит произвёл Joram Wilander
родитель 71d010b7af
Коммит b5ffdf5c54
3 изменённых файлов: 24 добавлений и 5 удалений

Просмотреть файл

@@ -15,7 +15,8 @@ export default class Reaction extends React.Component {
post: React.PropTypes.object.isRequired, post: React.PropTypes.object.isRequired,
currentUserId: React.PropTypes.string.isRequired, currentUserId: React.PropTypes.string.isRequired,
emojiName: React.PropTypes.string.isRequired, emojiName: React.PropTypes.string.isRequired,
reactions: React.PropTypes.arrayOf(React.PropTypes.object) reactions: React.PropTypes.arrayOf(React.PropTypes.object),
emojis: React.PropTypes.object.isRequired
} }
constructor(props) { constructor(props) {
@@ -36,7 +37,7 @@ export default class Reaction extends React.Component {
} }
render() { render() {
if (!EmojiStore.has(this.props.emojiName)) { if (!this.props.emojis.has(this.props.emojiName)) {
return null; return null;
} }
@@ -190,7 +191,7 @@ export default class Reaction extends React.Component {
> >
<span <span
className='post-reaction__emoji emoticon' className='post-reaction__emoji emoticon'
style={{backgroundImage: 'url(' + EmojiStore.getEmojiImageUrl(EmojiStore.get(this.props.emojiName)) + ')'}} style={{backgroundImage: 'url(' + EmojiStore.getEmojiImageUrl(this.props.emojis.get(this.props.emojiName)) + ')'}}
/> />
<span className='post-reaction__count'> <span className='post-reaction__count'>
{this.props.reactions.length} {this.props.reactions.length}

Просмотреть файл

@@ -4,6 +4,7 @@
import React from 'react'; import React from 'react';
import * as AsyncClient from 'utils/async_client.jsx'; import * as AsyncClient from 'utils/async_client.jsx';
import EmojiStore from 'stores/emoji_store.jsx';
import ReactionStore from 'stores/reaction_store.jsx'; import ReactionStore from 'stores/reaction_store.jsx';
import ReactionListView from './reaction_list_view.jsx'; import ReactionListView from './reaction_list_view.jsx';
@@ -18,14 +19,17 @@ export default class ReactionListContainer extends React.Component {
super(props); super(props);
this.handleReactionsChanged = this.handleReactionsChanged.bind(this); this.handleReactionsChanged = this.handleReactionsChanged.bind(this);
this.handleEmojisChanged = this.handleEmojisChanged.bind(this);
this.state = { this.state = {
reactions: ReactionStore.getReactions(this.props.post.id) reactions: ReactionStore.getReactions(this.props.post.id),
emojis: EmojiStore.getEmojis()
}; };
} }
componentDidMount() { componentDidMount() {
ReactionStore.addChangeListener(this.props.post.id, this.handleReactionsChanged); ReactionStore.addChangeListener(this.props.post.id, this.handleReactionsChanged);
EmojiStore.addChangeListener(this.handleEmojisChanged);
if (this.props.post.has_reactions) { if (this.props.post.has_reactions) {
AsyncClient.listReactions(this.props.post.channel_id, this.props.post.id); AsyncClient.listReactions(this.props.post.channel_id, this.props.post.id);
@@ -53,11 +57,16 @@ export default class ReactionListContainer extends React.Component {
return true; return true;
} }
if (nextState.emojis !== this.state.emojis) {
return true;
}
return false; return false;
} }
componentWillUnmount() { componentWillUnmount() {
ReactionStore.removeChangeListener(this.props.post.id, this.handleReactionsChanged); ReactionStore.removeChangeListener(this.props.post.id, this.handleReactionsChanged);
EmojiStore.removeChangeListener(this.handleEmojisChanged);
} }
handleReactionsChanged() { handleReactionsChanged() {
@@ -66,6 +75,12 @@ export default class ReactionListContainer extends React.Component {
}); });
} }
handleEmojisChanged() {
this.setState({
emojis: EmojiStore.getEmojis()
});
}
render() { render() {
if (!this.props.post.has_reactions) { if (!this.props.post.has_reactions) {
return null; return null;
@@ -76,6 +91,7 @@ export default class ReactionListContainer extends React.Component {
post={this.props.post} post={this.props.post}
currentUserId={this.props.currentUserId} currentUserId={this.props.currentUserId}
reactions={this.state.reactions} reactions={this.state.reactions}
emojis={this.state.emojis}
/> />
); );
} }

Просмотреть файл

@@ -9,7 +9,8 @@ export default class ReactionListView extends React.Component {
static propTypes = { static propTypes = {
post: React.PropTypes.object.isRequired, post: React.PropTypes.object.isRequired,
currentUserId: React.PropTypes.string.isRequired, currentUserId: React.PropTypes.string.isRequired,
reactions: React.PropTypes.arrayOf(React.PropTypes.object) reactions: React.PropTypes.arrayOf(React.PropTypes.object),
emojis: React.PropTypes.object.isRequired
} }
render() { render() {
@@ -35,6 +36,7 @@ export default class ReactionListView extends React.Component {
currentUserId={this.props.currentUserId} currentUserId={this.props.currentUserId}
emojiName={emojiName} emojiName={emojiName}
reactions={reactionsByName.get(emojiName)} reactions={reactionsByName.get(emojiName)}
emojis={this.props.emojis}
/> />
); );
}); });