Merge pull request #2594 from mattermost/plt-2476

PLT-2476 Fixing username display in center channel
Этот коммит содержится в:
Harrison Healey
2016-03-31 13:01:05 -04:00
родитель 720947e17e 54a064de98
Коммит 36f611fac4
5 изменённых файлов: 38 добавлений и 54 удалений

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

@@ -8,7 +8,6 @@ import PostsViewContainer from 'components/posts_view_container.jsx';
import CreatePost from 'components/create_post.jsx'; import CreatePost from 'components/create_post.jsx';
import ChannelStore from 'stores/channel_store.jsx'; import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx';
export default class ChannelView extends React.Component { export default class ChannelView extends React.Component {
constructor(props) { constructor(props) {
@@ -23,14 +22,12 @@ export default class ChannelView extends React.Component {
getStateFromStores(props) { getStateFromStores(props) {
const channel = ChannelStore.getByName(props.params.channel); const channel = ChannelStore.getByName(props.params.channel);
const channelId = channel ? channel.id : ''; const channelId = channel ? channel.id : '';
const profiles = JSON.parse(JSON.stringify(UserStore.getProfiles()));
return { return {
channelId, channelId
profiles
}; };
} }
isStateValid() { isStateValid() {
return this.state.channelId !== '' && this.state.profiles; return this.state.channelId !== '';
} }
updateState() { updateState() {
this.setState(this.getStateFromStores(this.props)); this.setState(this.getStateFromStores(this.props));
@@ -44,13 +41,6 @@ export default class ChannelView extends React.Component {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
this.setState(this.getStateFromStores(nextProps)); this.setState(this.getStateFromStores(nextProps));
} }
shouldComponentUpdate(nextProps, nextState) {
if (nextState.channelId !== this.state.channelId) {
return true;
}
return false;
}
render() { render() {
return ( return (
<div <div
@@ -60,7 +50,7 @@ export default class ChannelView extends React.Component {
<ChannelHeader <ChannelHeader
channelId={this.state.channelId} channelId={this.state.channelId}
/> />
<PostsViewContainer profiles={this.state.profiles}/> <PostsViewContainer profiles={this.props.profiles}/>
<div <div
className='post-create__container' className='post-create__container'
id='post-create' id='post-create'
@@ -75,5 +65,6 @@ ChannelView.defaultProps = {
}; };
ChannelView.propTypes = { ChannelView.propTypes = {
params: React.PropTypes.object.isRequired params: React.PropTypes.object.isRequired,
profiles: React.PropTypes.object
}; };

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

@@ -50,6 +50,7 @@ class InviteMemberModal extends React.Component {
constructor(props) { constructor(props) {
super(props); super(props);
this.teamChange = this.teamChange.bind(this);
this.handleToggle = this.handleToggle.bind(this); this.handleToggle = this.handleToggle.bind(this);
this.handleSubmit = this.handleSubmit.bind(this); this.handleSubmit = this.handleSubmit.bind(this);
this.handleHide = this.handleHide.bind(this); this.handleHide = this.handleHide.bind(this);
@@ -68,16 +69,27 @@ class InviteMemberModal extends React.Component {
emailEnabled: global.window.mm_config.SendEmailNotifications === 'true', emailEnabled: global.window.mm_config.SendEmailNotifications === 'true',
userCreationEnabled: global.window.mm_config.EnableUserCreation === 'true', userCreationEnabled: global.window.mm_config.EnableUserCreation === 'true',
showConfirmModal: false, showConfirmModal: false,
isSendingEmails: false isSendingEmails: false,
teamType: null
}; };
} }
teamChange() {
const team = TeamStore.getCurrent();
const teamType = team ? team.type : null;
this.setState({
teamType
});
}
componentDidMount() { componentDidMount() {
ModalStore.addModalListener(ActionTypes.TOGGLE_INVITE_MEMBER_MODAL, this.handleToggle); ModalStore.addModalListener(ActionTypes.TOGGLE_INVITE_MEMBER_MODAL, this.handleToggle);
TeamStore.addChangeListener(this.teamChange);
} }
componentWillUnmount() { componentWillUnmount() {
ModalStore.removeModalListener(ActionTypes.TOGGLE_INVITE_MEMBER_MODAL, this.handleToggle); ModalStore.removeModalListener(ActionTypes.TOGGLE_INVITE_MEMBER_MODAL, this.handleToggle);
TeamStore.removeChangeListener(this.teamChange);
} }
handleToggle(value) { handleToggle(value) {
@@ -224,7 +236,7 @@ class InviteMemberModal extends React.Component {
var currentUser = UserStore.getCurrentUser(); var currentUser = UserStore.getCurrentUser();
const {formatMessage} = this.props.intl; const {formatMessage} = this.props.intl;
if (currentUser != null) { if (currentUser != null && this.state.teamType != null) {
var inviteSections = []; var inviteSections = [];
var inviteIds = this.state.inviteIds; var inviteIds = this.state.inviteIds;
for (var i = 0; i < inviteIds.length; i++) { for (var i = 0; i < inviteIds.length; i++) {
@@ -398,7 +410,7 @@ class InviteMemberModal extends React.Component {
); );
} else if (this.state.userCreationEnabled) { } else if (this.state.userCreationEnabled) {
var teamInviteLink = null; var teamInviteLink = null;
if (currentUser && TeamStore.getCurrent().type === 'O') { if (currentUser && this.state.teamType === 'O') {
var link = ( var link = (
<a <a
href='#' href='#'

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

@@ -47,11 +47,12 @@ export default class LoggedIn extends React.Component {
this.onUserChanged = this.onUserChanged.bind(this); this.onUserChanged = this.onUserChanged.bind(this);
this.state = { this.state = {
user: null user: null,
profiles: null
}; };
} }
isValidState() { isValidState() {
return this.state.user != null; return this.state.user != null && this.state.profiles != null;
} }
onUserChanged() { onUserChanged() {
// Grab the current user // Grab the current user
@@ -84,7 +85,13 @@ export default class LoggedIn extends React.Component {
browserHistory.push(Utils.getTeamURLFromAddressBar() + '/tutorial'); browserHistory.push(Utils.getTeamURLFromAddressBar() + '/tutorial');
} }
this.setState({user}); // Get profiles
const profiles = UserStore.getProfiles();
this.setState({
user,
profiles
});
} }
componentWillMount() { componentWillMount() {
// Emit view action // Emit view action
@@ -232,7 +239,10 @@ export default class LoggedIn extends React.Component {
</div> </div>
</div> </div>
<div className='row main'> <div className='row main'>
{this.props.center} {React.cloneElement(this.props.center, {
user: this.state.user,
profiles: this.state.profiles
})}
</div> </div>
</div> </div>
); );

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

@@ -7,7 +7,6 @@ import ChannelHeader from 'components/channel_header.jsx';
import PostFocusView from 'components/post_focus_view.jsx'; import PostFocusView from 'components/post_focus_view.jsx';
import ChannelStore from 'stores/channel_store.jsx'; import ChannelStore from 'stores/channel_store.jsx';
import UserStore from 'stores/user_store.jsx';
import TeamStore from 'stores/team_store.jsx'; import TeamStore from 'stores/team_store.jsx';
import {Link} from 'react-router'; import {Link} from 'react-router';
@@ -30,17 +29,15 @@ export default class PermalinkView extends React.Component {
const channelName = channel ? channel.name : ''; const channelName = channel ? channel.name : '';
const team = TeamStore.getCurrent(); const team = TeamStore.getCurrent();
const teamName = team ? team.name : ''; const teamName = team ? team.name : '';
const profiles = JSON.parse(JSON.stringify(UserStore.getProfiles()));
return { return {
channelId, channelId,
channelName, channelName,
profiles,
teamName, teamName,
postId postId
}; };
} }
isStateValid() { isStateValid() {
return this.state.channelId !== '' && this.state.profiles && this.state.teamName; return this.state.channelId !== '' && this.state.teamName;
} }
updateState() { updateState() {
this.setState(this.getStateFromStores(this.props)); this.setState(this.getStateFromStores(this.props));
@@ -56,21 +53,6 @@ export default class PermalinkView extends React.Component {
componentWillReceiveProps(nextProps) { componentWillReceiveProps(nextProps) {
this.setState(this.getStateFromStores(nextProps)); this.setState(this.getStateFromStores(nextProps));
} }
shouldComponentUpdate(nextProps, nextState) {
if (nextState.postId !== this.state.postId) {
return true;
}
if (nextState.channelId !== this.state.channelId) {
return true;
}
if (nextState.teamName !== this.state.teamName) {
return true;
}
return false;
}
render() { render() {
if (!this.isStateValid()) { if (!this.isStateValid()) {
return null; return null;
@@ -83,7 +65,7 @@ export default class PermalinkView extends React.Component {
<ChannelHeader <ChannelHeader
channelId={this.state.channelId} channelId={this.state.channelId}
/> />
<PostFocusView profiles={this.state.profiles}/> <PostFocusView profiles={this.props.profiles}/>
<div <div
id='archive-link-home' id='archive-link-home'
> >
@@ -106,5 +88,6 @@ PermalinkView.defaultProps = {
}; };
PermalinkView.propTypes = { PermalinkView.propTypes = {
params: React.PropTypes.object.isRequired params: React.PropTypes.object.isRequired,
profiles: React.PropTypes.object
}; };

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

@@ -8,7 +8,6 @@ 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 UserStore from 'stores/user_store.jsx';
import * as Utils from 'utils/utils.jsx';
import * as GlobalActions from 'action_creators/global_actions.jsx'; import * as GlobalActions from 'action_creators/global_actions.jsx';
import Constants from 'utils/constants.jsx'; import Constants from 'utils/constants.jsx';
@@ -158,17 +157,6 @@ export default class PostsViewContainer extends React.Component {
this.setState({scrollType: PostsView.SCROLL_TYPE_FREE}); this.setState({scrollType: PostsView.SCROLL_TYPE_FREE});
} }
} }
shouldComponentUpdate(nextProps, nextState) {
if (!Utils.areObjectsEqual(this.state, nextState)) {
return true;
}
if (!Utils.areObjectsEqual(this.props, nextProps)) {
return true;
}
return false;
}
render() { render() {
const postLists = this.state.postLists; const postLists = this.state.postLists;
const channels = this.state.channels; const channels = this.state.channels;