Move post view container user store listener into center panel and pass profiles into post focus view

Этот коммит содержится в:
JoramWilander
2016-02-25 12:59:24 -05:00
родитель 4153507462
Коммит 493722b8f2
3 изменённых файлов: 13 добавлений и 14 удалений

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

@@ -33,7 +33,8 @@ export default class CenterPanel extends React.Component {
this.state = { this.state = {
showTutorialScreens: tutorialStep === TutorialSteps.INTRO_SCREENS, showTutorialScreens: tutorialStep === TutorialSteps.INTRO_SCREENS,
showPostFocus: ChannelStore.getPostMode() === ChannelStore.POST_MODE_FOCUS, showPostFocus: ChannelStore.getPostMode() === ChannelStore.POST_MODE_FOCUS,
user: UserStore.getCurrentUser() user: UserStore.getCurrentUser(),
profiles: JSON.parse(JSON.stringify(UserStore.getProfiles()))
}; };
} }
componentDidMount() { componentDidMount() {
@@ -54,7 +55,7 @@ export default class CenterPanel extends React.Component {
this.setState({showPostFocus: ChannelStore.getPostMode() === ChannelStore.POST_MODE_FOCUS}); this.setState({showPostFocus: ChannelStore.getPostMode() === ChannelStore.POST_MODE_FOCUS});
} }
onUserChange() { onUserChange() {
this.setState({user: UserStore.getCurrentUser()}); this.setState({user: UserStore.getCurrentUser(), profiles: JSON.parse(JSON.stringify(UserStore.getProfiles()))});
} }
render() { render() {
const channel = ChannelStore.getCurrent(); const channel = ChannelStore.getCurrent();
@@ -65,7 +66,7 @@ export default class CenterPanel extends React.Component {
postsContainer = <TutorialIntroScreens/>; postsContainer = <TutorialIntroScreens/>;
createPost = null; createPost = null;
} else if (this.state.showPostFocus) { } else if (this.state.showPostFocus) {
postsContainer = <PostFocusView/>; postsContainer = <PostFocusView profiles={this.state.profiles}/>;
handleClick = function clickHandler(e) { handleClick = function clickHandler(e) {
e.preventDefault(); e.preventDefault();
@@ -87,7 +88,7 @@ export default class CenterPanel extends React.Component {
</div> </div>
); );
} else { } else {
postsContainer = <PostsViewContainer/>; postsContainer = <PostsViewContainer profiles={this.state.profiles}/>;
createPost = ( createPost = (
<div <div
className='post-create__container' className='post-create__container'

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

@@ -105,6 +105,7 @@ export default class PostFocusView extends React.Component {
introText={this.getIntroMessage()} introText={this.getIntroMessage()}
messageSeparatorTime={0} messageSeparatorTime={0}
postsToHighlight={postsToHighlight} postsToHighlight={postsToHighlight}
profiles={this.props.profiles}
/> />
</div> </div>
); );
@@ -114,4 +115,5 @@ PostFocusView.defaultProps = {
}; };
PostFocusView.propTypes = { PostFocusView.propTypes = {
profiles: React.PropTypes.object
}; };

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

@@ -6,7 +6,6 @@ import LoadingScreen from './loading_screen.jsx';
import ChannelStore from '../stores/channel_store.jsx'; import ChannelStore from '../stores/channel_store.jsx';
import PostStore from '../stores/post_store.jsx'; import PostStore from '../stores/post_store.jsx';
import UserStore from '../stores/user_store.jsx';
import * as Utils from '../utils/utils.jsx'; import * as Utils from '../utils/utils.jsx';
import * as EventHelpers from '../dispatcher/event_helpers.jsx'; import * as EventHelpers from '../dispatcher/event_helpers.jsx';
@@ -25,13 +24,11 @@ export default class PostsViewContainer extends React.Component {
this.handlePostsViewScroll = this.handlePostsViewScroll.bind(this); this.handlePostsViewScroll = this.handlePostsViewScroll.bind(this);
this.loadMorePostsTop = this.loadMorePostsTop.bind(this); this.loadMorePostsTop = this.loadMorePostsTop.bind(this);
this.handlePostsViewJumpRequest = this.handlePostsViewJumpRequest.bind(this); this.handlePostsViewJumpRequest = this.handlePostsViewJumpRequest.bind(this);
this.onUserChange = this.onUserChange.bind(this);
const currentChannelId = ChannelStore.getCurrentId(); const currentChannelId = ChannelStore.getCurrentId();
const state = { const state = {
scrollType: PostsView.SCROLL_TYPE_BOTTOM, scrollType: PostsView.SCROLL_TYPE_BOTTOM,
scrollPost: null, scrollPost: null
profiles: JSON.parse(JSON.stringify(UserStore.getProfiles()))
}; };
if (currentChannelId) { if (currentChannelId) {
Object.assign(state, { Object.assign(state, {
@@ -57,14 +54,12 @@ export default class PostsViewContainer extends React.Component {
ChannelStore.addLeaveListener(this.onChannelLeave); ChannelStore.addLeaveListener(this.onChannelLeave);
PostStore.addChangeListener(this.onPostsChange); PostStore.addChangeListener(this.onPostsChange);
PostStore.addPostsViewJumpListener(this.handlePostsViewJumpRequest); PostStore.addPostsViewJumpListener(this.handlePostsViewJumpRequest);
UserStore.addChangeListener(this.onUserChange);
} }
componentWillUnmount() { componentWillUnmount() {
ChannelStore.removeChangeListener(this.onChannelChange); ChannelStore.removeChangeListener(this.onChannelChange);
ChannelStore.removeLeaveListener(this.onChannelLeave); ChannelStore.removeLeaveListener(this.onChannelLeave);
PostStore.removeChangeListener(this.onPostsChange); PostStore.removeChangeListener(this.onPostsChange);
PostStore.removePostsViewJumpListener(this.handlePostsViewJumpRequest); PostStore.removePostsViewJumpListener(this.handlePostsViewJumpRequest);
UserStore.removeChangeListener(this.onUserChange);
} }
handlePostsViewJumpRequest(type, post) { handlePostsViewJumpRequest(type, post) {
switch (type) { switch (type) {
@@ -140,9 +135,6 @@ export default class PostsViewContainer extends React.Component {
atTop[this.state.currentChannelIndex] = PostStore.getVisibilityAtTop(currentChannelId); atTop[this.state.currentChannelIndex] = PostStore.getVisibilityAtTop(currentChannelId);
this.setState({postLists, atTop}); this.setState({postLists, atTop});
} }
onUserChange() {
this.setState({profiles: JSON.parse(JSON.stringify(UserStore.getProfiles()))});
}
getChannelPosts(id) { getChannelPosts(id) {
return PostStore.getVisiblePosts(id); return PostStore.getVisiblePosts(id);
} }
@@ -188,7 +180,7 @@ export default class PostsViewContainer extends React.Component {
showMoreMessagesBottom={false} showMoreMessagesBottom={false}
introText={channel ? createChannelIntroMessage(channel) : null} introText={channel ? createChannelIntroMessage(channel) : null}
messageSeparatorTime={this.state.currentLastViewed} messageSeparatorTime={this.state.currentLastViewed}
profiles={this.state.profiles} profiles={this.props.profiles}
/> />
); );
if (!postLists[i] && isActive) { if (!postLists[i] && isActive) {
@@ -208,3 +200,7 @@ export default class PostsViewContainer extends React.Component {
); );
} }
} }
PostsViewContainer.propTypes = {
profiles: React.PropTypes.object
};