Files
mattermost/webapp/components/sidebar_header.jsx

134 lines
4.0 KiB
React
Raw Normal View History

import PropTypes from 'prop-types';
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
2015-06-14 23:53:32 -08:00
// See License.txt for license information.
import React from 'react';
2015-10-30 11:35:16 -04:00
2016-03-14 08:50:46 -04:00
import PreferenceStore from 'stores/preference_store.jsx';
import * as Utils from 'utils/utils.jsx';
2015-06-14 23:53:32 -08:00
import SidebarHeaderDropdown from './sidebar_header_dropdown.jsx';
2016-03-14 08:50:46 -04:00
import {Tooltip, OverlayTrigger} from 'react-bootstrap';
import {Preferences, TutorialSteps, Constants} from 'utils/constants.jsx';
import {createMenuTip} from 'components/tutorial/tutorial_tip.jsx';
import StatusDropdown from 'components/status_dropdown/index.jsx';
export default class SidebarHeader extends React.Component {
constructor(props) {
super(props);
2015-07-23 14:59:43 +05:00
2015-10-30 11:35:16 -04:00
this.state = this.getStateFromStores();
}
2015-10-30 11:35:16 -04:00
componentDidMount() {
PreferenceStore.addChangeListener(this.onPreferenceChange);
window.addEventListener('resize', this.handleResize);
2015-10-30 11:35:16 -04:00
}
2015-10-30 11:35:16 -04:00
componentWillUnmount() {
PreferenceStore.removeChangeListener(this.onPreferenceChange);
window.removeEventListener('resize', this.handleResize);
}
handleResize = () => {
const isMobile = Utils.isMobile();
this.setState({isMobile});
2015-10-30 11:35:16 -04:00
}
getPreferences = () => {
if (!this.props.currentUser) {
return {};
}
2016-02-08 07:26:10 -05:00
const tutorialStep = PreferenceStore.getInt(Preferences.TUTORIAL_STEP, this.props.currentUser.id, 999);
const showTutorialTip = tutorialStep === TutorialSteps.MENU_POPOVER && !Utils.isMobile();
2015-10-30 11:35:16 -04:00
return {showTutorialTip};
2015-10-30 11:35:16 -04:00
}
getStateFromStores = () => {
const preferences = this.getPreferences();
const isMobile = Utils.isMobile();
return {...preferences, isMobile};
2015-06-14 23:53:32 -08:00
}
onPreferenceChange = () => {
this.setState(this.getPreferences());
}
toggleDropdown = (e) => {
2015-09-17 22:00:33 -07:00
e.preventDefault();
this.refs.dropdown.toggleDropdown();
}
renderStatusDropdown = () => {
if (this.state.isMobile) {
return null;
}
return (
<StatusDropdown/>
);
}
2015-06-14 23:53:32 -08:00
render() {
const statusDropdown = this.renderStatusDropdown();
2015-08-04 09:40:58 -07:00
2015-10-30 11:35:16 -04:00
let tutorialTip = null;
if (this.state.showTutorialTip) {
tutorialTip = createMenuTip(this.toggleDropdown);
2015-10-30 11:35:16 -04:00
}
let teamNameWithToolTip = null;
if (this.props.teamDescription === '') {
teamNameWithToolTip = (
<div className='team__name'>{this.props.teamDisplayName}</div>
);
} else {
teamNameWithToolTip = (
<OverlayTrigger
trigger={['hover', 'focus']}
delayShow={Constants.OVERLAY_TIME_DELAY}
placement='bottom'
overlay={<Tooltip id='team-name__tooltip'>{this.props.teamDescription}</Tooltip>}
ref='descriptionOverlay'
>
<div className='team__name'>{this.props.teamDisplayName}</div>
</OverlayTrigger>
);
}
2015-06-14 23:53:32 -08:00
return (
2015-08-04 09:40:58 -07:00
<div className='team__header theme'>
2015-10-30 11:35:16 -04:00
{tutorialTip}
<div className='header__info'>
<div className='user__name'>{'@' + this.props.currentUser.username}</div>
{teamNameWithToolTip}
</div>
<SidebarHeaderDropdown
ref='dropdown'
teamType={this.props.teamType}
teamDisplayName={this.props.teamDisplayName}
teamName={this.props.teamName}
2016-02-08 07:26:10 -05:00
currentUser={this.props.currentUser}
/>
{statusDropdown}
2015-06-14 23:53:32 -08:00
</div>
);
}
}
SidebarHeader.defaultProps = {
2016-02-08 07:26:10 -05:00
teamDisplayName: '',
teamDescription: '',
teamType: ''
};
SidebarHeader.propTypes = {
teamDisplayName: PropTypes.string,
teamDescription: PropTypes.string,
teamName: PropTypes.string,
teamType: PropTypes.string,
currentUser: PropTypes.object
};