From 1cc68197d2e1a922149a46211cbd1079bfe3556c Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Wed, 13 Jan 2016 22:07:37 +0900 Subject: [PATCH] Hide tabs when the number of teams is 1 --- src/browser/index.jsx | 61 +++++++++++++++++++++++++++---------------- test/browser_test.js | 14 +++++++++- 2 files changed, 52 insertions(+), 23 deletions(-) diff --git a/src/browser/index.jsx b/src/browser/index.jsx index f961cae1..38be3d3f 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -55,7 +55,7 @@ var MainPage = React.createClass({ var visibility = visible ? 'visible' : 'hidden'; return { position: 'absolute', - top: 42, + top: (this.props.teams.length > 1) ? 42 : 0, right: 0, bottom: 0, left: 0, @@ -64,19 +64,16 @@ var MainPage = React.createClass({ }, render: function() { var thisObj = this; - var tabs = this.props.teams.map(function(team, index) { - var badge; - if (thisObj.state.unreadCounts[index] != 0) { - badge = ( - { thisObj.state.unreadCounts[index] } - ); - } - return ( - { team.name } - { ' ' } - { badge } - ); - }); + + var tabs_row; + if (this.props.teams.length > 1) { + tabs_row = ( + + + + ); + } + var views = this.props.teams.map(function(team, index) { var handleUnreadCountChange = function(count) { thisObj.handleUnreadCountChange(index, count); @@ -87,21 +84,41 @@ var MainPage = React.createClass({ return () }); + var views_row = ( + { views } + ); return ( - - - - - { views } - + { tabs_row } + { views_row } ); } }); +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 = ( + { thisObj.props.unreadCounts[index] } + ); + } + return ( + { team.name } + { ' ' } + { badge } + ); + }); + return ( + + ); + } +}); var MattermostView = React.createClass({ getInitialState: function() { diff --git a/test/browser_test.js b/test/browser_test.js index a689e9e2..746ce496 100644 --- a/test/browser_test.js +++ b/test/browser_test.js @@ -106,10 +106,22 @@ describe('electron-mattermost', function() { }] }; - before(function() { + beforeEach(function() { 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() { return client .init()