Hide tabs when the number of teams is 1

This commit is contained in:
Yuya Ochiai
2016-01-13 22:07:37 +09:00
parent 48f63b6bcb
commit 1cc68197d2
2 changed files with 52 additions and 23 deletions

View File

@@ -55,7 +55,7 @@ var MainPage = React.createClass({
var visibility = visible ? 'visible' : 'hidden'; var visibility = visible ? 'visible' : 'hidden';
return { return {
position: 'absolute', position: 'absolute',
top: 42, top: (this.props.teams.length > 1) ? 42 : 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
left: 0, left: 0,
@@ -64,19 +64,16 @@ var MainPage = React.createClass({
}, },
render: function() { render: function() {
var thisObj = this; var thisObj = this;
var tabs = this.props.teams.map(function(team, index) {
var badge; var tabs_row;
if (thisObj.state.unreadCounts[index] != 0) { if (this.props.teams.length > 1) {
badge = (<Badge> tabs_row = (
{ thisObj.state.unreadCounts[index] } <Row>
</Badge>); <TabBar id="tabBar" teams={ this.props.teams } unreadCounts={ this.state.unreadCounts } activeKey={ this.state.key } onSelect={ this.handleSelect }></TabBar>
} </Row>
return (<NavItem className="teamTabItem" id={ 'teamTabItem' + index } eventKey={ index }> );
{ team.name } }
{ ' ' }
{ badge }
</NavItem>);
});
var views = this.props.teams.map(function(team, index) { var views = this.props.teams.map(function(team, index) {
var handleUnreadCountChange = function(count) { var handleUnreadCountChange = function(count) {
thisObj.handleUnreadCountChange(index, count); thisObj.handleUnreadCountChange(index, count);
@@ -87,21 +84,41 @@ var MainPage = React.createClass({
return (<MattermostView id={ 'mattermostView' + index } style={ thisObj.visibleStyle(thisObj.state.key === index) } src={ team.url } onUnreadCountChange={ handleUnreadCountChange } onNotificationClick={ handleNotificationClick } return (<MattermostView id={ 'mattermostView' + index } style={ thisObj.visibleStyle(thisObj.state.key === index) } src={ team.url } onUnreadCountChange={ handleUnreadCountChange } onNotificationClick={ handleNotificationClick }
/>) />)
}); });
var views_row = (<Row>
{ views }
</Row>);
return ( return (
<Grid fluid> <Grid fluid>
<Row> { tabs_row }
<Nav bsStyle="tabs" activeKey={ this.state.key } onSelect={ this.handleSelect }> { views_row }
{ tabs }
</Nav>
</Row>
<Row>
{ views }
</Row>
</Grid> </Grid>
); );
} }
}); });
var TabBar = React.createClass({
render: function() {
var thisObj = this;
var tabs = this.props.teams.map(function(team, index) {
var badge;
if (thisObj.props.unreadCounts[index] != 0) {
badge = (<Badge>
{ thisObj.props.unreadCounts[index] }
</Badge>);
}
return (<NavItem className="teamTabItem" id={ 'teamTabItem' + index } eventKey={ index }>
{ team.name }
{ ' ' }
{ badge }
</NavItem>);
});
return (
<Nav id={ this.props.id } bsStyle="tabs" activeKey={ this.props.activeKey } onSelect={ this.props.onSelect }>
{ tabs }
</Nav>
);
}
});
var MattermostView = React.createClass({ var MattermostView = React.createClass({
getInitialState: function() { getInitialState: function() {

View File

@@ -106,10 +106,22 @@ describe('electron-mattermost', function() {
}] }]
}; };
before(function() { beforeEach(function() {
fs.writeFileSync(config_file_path, JSON.stringify(config)); fs.writeFileSync(config_file_path, JSON.stringify(config));
}); });
it('should NOT show tabs when there is one team', function() {
fs.writeFileSync(config_file_path, JSON.stringify({
url: mattermost_url
}));
return client
.init()
.isExisting('#tabBar').then(function(isExisting) {
isExisting.should.be.false();
})
.end();
});
it('should set src of webview from config file', function() { it('should set src of webview from config file', function() {
return client return client
.init() .init()