mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
* Updating client dependancies. Switching to using yarn. * Updating React * Moving pure components to using function syntax (performance gains with newer react version) * Updating client dependancies. * Ignore .yarninstall * Enabling pre-lockfile because it's the entire point of using yarn. * Removing old webpack config * Moving to new prop-types * Fixing ESLint Errors * Updating jest snapshots. * Cleaning up package.json
97 lines
2.7 KiB
JavaScript
97 lines
2.7 KiB
JavaScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See License.txt for license information.
|
|
|
|
import $ from 'jquery';
|
|
import PropTypes from 'prop-types';
|
|
import React from 'react';
|
|
|
|
import * as UserAgent from 'utils/user_agent.jsx';
|
|
import ChannelHeader from 'components/channel_header.jsx';
|
|
import FileUploadOverlay from 'components/file_upload_overlay.jsx';
|
|
import CreatePost from 'components/create_post.jsx';
|
|
import PostViewCache from 'components/post_view';
|
|
|
|
import ChannelStore from 'stores/channel_store.jsx';
|
|
|
|
import * as Utils from 'utils/utils.jsx';
|
|
|
|
export default class ChannelView extends React.Component {
|
|
constructor(props) {
|
|
super(props);
|
|
|
|
this.getStateFromStores = this.getStateFromStores.bind(this);
|
|
this.isStateValid = this.isStateValid.bind(this);
|
|
this.updateState = this.updateState.bind(this);
|
|
|
|
this.state = this.getStateFromStores(props);
|
|
}
|
|
getStateFromStores(props) {
|
|
const channel = ChannelStore.getByName(props.params.channel);
|
|
const channelId = channel ? channel.id : '';
|
|
return {
|
|
channelId
|
|
};
|
|
}
|
|
isStateValid() {
|
|
return this.state.channelId !== '';
|
|
}
|
|
updateState() {
|
|
this.setState(this.getStateFromStores(this.props));
|
|
}
|
|
componentDidMount() {
|
|
ChannelStore.addChangeListener(this.updateState);
|
|
|
|
$('body').addClass('app__body');
|
|
|
|
// IE Detection
|
|
if (UserAgent.isInternetExplorer()) {
|
|
$('body').addClass('browser--ie');
|
|
}
|
|
}
|
|
componentWillUnmount() {
|
|
ChannelStore.removeChangeListener(this.updateState);
|
|
|
|
$('body').removeClass('app__body');
|
|
}
|
|
componentWillReceiveProps(nextProps) {
|
|
this.setState(this.getStateFromStores(nextProps));
|
|
}
|
|
shouldComponentUpdate(nextProps, nextState) {
|
|
if (!Utils.areObjectsEqual(nextProps.params, this.props.params)) {
|
|
return true;
|
|
}
|
|
|
|
if (nextState.channelId !== this.state.channelId) {
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
render() {
|
|
return (
|
|
<div
|
|
id='app-content'
|
|
className='app__content'
|
|
>
|
|
<FileUploadOverlay overlayType='center'/>
|
|
<ChannelHeader
|
|
channelId={this.state.channelId}
|
|
/>
|
|
<PostViewCache/>
|
|
<div
|
|
className='post-create__container'
|
|
id='post-create'
|
|
>
|
|
<CreatePost/>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
}
|
|
ChannelView.defaultProps = {
|
|
};
|
|
|
|
ChannelView.propTypes = {
|
|
params: PropTypes.object.isRequired
|
|
};
|