Move post_body profile change listener into posts view

Этот коммит содержится в:
JoramWilander
2016-02-22 11:09:35 -05:00
родитель 9b30fad8ad
Коммит c16071afc5
4 изменённых файлов: 28 добавлений и 21 удалений

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

@@ -147,8 +147,8 @@ export default class ChannelHeader extends React.Component {
</Popover>
);
let channelTitle = channel.display_name;
const currentId = this.prop.user.id;
const isAdmin = Utils.isAdmin(this.state.memberChannel.roles) || Utils.isAdmin(this.state.memberTeam.roles);
const currentId = this.props.user.id;
const isAdmin = Utils.isAdmin(this.state.memberChannel.roles) || Utils.isAdmin(this.props.user.roles);
const isDirect = (this.state.channel.type === 'D');
if (isDirect) {

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

@@ -99,6 +99,10 @@ export default class Post extends React.Component {
return true;
}
if (nextProps.hasProfiles !== this.props.hasProfiles) {
return true;
}
return false;
}
getCommentCount(props) {
@@ -223,6 +227,7 @@ export default class Post extends React.Component {
posts={posts}
handleCommentClick={this.handleCommentClick}
retryPost={this.retryPost}
hasProfiles={this.props.hasProfiles}
/>
</div>
</div>
@@ -233,7 +238,7 @@ export default class Post extends React.Component {
}
Post.propTypes = {
post: React.PropTypes.object,
post: React.PropTypes.object.isRequired,
posts: React.PropTypes.object,
parentPost: React.PropTypes.object,
sameUser: React.PropTypes.bool,
@@ -241,5 +246,6 @@ Post.propTypes = {
hideProfilePic: React.PropTypes.bool,
isLastComment: React.PropTypes.bool,
shouldHighlight: React.PropTypes.bool,
displayNameType: React.PropTypes.string
displayNameType: React.PropTypes.string,
hasProfiles: React.PropTypes.bool
};

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

@@ -33,7 +33,6 @@ class PostBody extends React.Component {
this.isImgLoading = false;
this.handleUserChange = this.handleUserChange.bind(this);
this.parseEmojis = this.parseEmojis.bind(this);
this.createEmbed = this.createEmbed.bind(this);
this.createImageEmbed = this.createImageEmbed.bind(this);
@@ -80,26 +79,12 @@ class PostBody extends React.Component {
componentDidMount() {
this.parseEmojis();
UserStore.addChangeListener(this.handleUserChange);
}
componentDidUpdate() {
this.parseEmojis();
}
componentWillUnmount() {
UserStore.removeChangeListener(this.handleUserChange);
}
handleUserChange() {
if (!this.state.hasProfiles) {
const profiles = UserStore.getProfiles();
this.setState({hasProfiles: profiles && Object.keys(profiles).length > 1});
}
}
componentWillReceiveProps(nextProps) {
const linkData = Utils.extractLinks(nextProps.post.message);
if (this.props.post.filenames.length === 0 && this.state.links && this.state.links.length > 0) {
@@ -357,7 +342,8 @@ PostBody.propTypes = {
post: React.PropTypes.object.isRequired,
parentPost: React.PropTypes.object,
retryPost: React.PropTypes.func.isRequired,
handleCommentClick: React.PropTypes.func.isRequired
handleCommentClick: React.PropTypes.func.isRequired,
hasProfiles: React.PropTypes.bool
};
export default injectIntl(PostBody);

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

@@ -28,6 +28,7 @@ export default class PostsView extends React.Component {
this.handleResize = this.handleResize.bind(this);
this.scrollToBottom = this.scrollToBottom.bind(this);
this.scrollToBottomAnimated = this.scrollToBottomAnimated.bind(this);
this.onUserChange = this.onUserChange.bind(this);
this.jumpToPostNode = null;
this.wasAtBottom = true;
@@ -38,7 +39,8 @@ export default class PostsView extends React.Component {
this.state = {
displayNameType: PreferenceStore.get(Preferences.CATEGORY_DISPLAY_SETTINGS, 'name_format', 'false'),
isScrolling: false,
topPostId: null
topPostId: null,
hasProfiles: false
};
}
static get SCROLL_TYPE_FREE() {
@@ -242,6 +244,7 @@ export default class PostsView extends React.Component {
shouldHighlight={shouldHighlight}
onClick={() => EventHelpers.emitPostFocusEvent(post.id)} //eslint-disable-line no-loop-func
displayNameType={this.state.displayNameType}
hasProfiles={this.state.hasProfiles}
/>
);
@@ -367,9 +370,11 @@ export default class PostsView extends React.Component {
if (this.props.postList != null) {
this.updateScrolling();
}
UserStore.addChangeListener(this.onUserChange);
window.addEventListener('resize', this.handleResize);
}
componentWillUnmount() {
UserStore.removeChangeListener(this.onUserChange);
window.removeEventListener('resize', this.handleResize);
}
componentDidUpdate() {
@@ -413,9 +418,19 @@ export default class PostsView extends React.Component {
if (this.state.isScrolling !== nextState.isScrolling) {
return true;
}
if (this.state.hasProfiles !== nextState.hasProfiles) {
return true;
}
return false;
}
onUserChange() {
if (!this.state.hasProfiles) {
const profiles = UserStore.getProfiles();
this.setState({hasProfiles: profiles && Object.keys(profiles).length > 1});
}
}
render() {
let posts = [];
let order = [];