From 390c67a7fd7badced915ec85609beeb16b1922fd Mon Sep 17 00:00:00 2001 From: Yuya Ochiai Date: Wed, 23 Dec 2015 16:21:33 +0900 Subject: [PATCH] Show unread count badge for each tabs --- src/browser/index.jsx | 44 +++++++++++++++++++++++++++++++++---------- 1 file changed, 34 insertions(+), 10 deletions(-) diff --git a/src/browser/index.jsx b/src/browser/index.jsx index 5800ced9..86f9ae5e 100644 --- a/src/browser/index.jsx +++ b/src/browser/index.jsx @@ -3,8 +3,9 @@ const Grid = ReactBootstrap.Grid; const Row = ReactBootstrap.Row; const Col = ReactBootstrap.Col; -const Tabs = ReactBootstrap.Tabs; -const Tab = ReactBootstrap.Tab; +const Nav = ReactBootstrap.Nav; +const NavItem = ReactBootstrap.NavItem; +const Badge = ReactBootstrap.Badge; const electron = require('electron'); const remote = electron.remote; @@ -18,12 +19,20 @@ const settings = require('../common/settings'); var MainPage = React.createClass({ getInitialState: function() { return { - key: 0 + key: 0, + unreadCounts: new Array(this.props.teams.length) }; }, handleSelect: function(key) { this.setState({ - key + key: key + }); + }, + handleUnreadCountChange: function(index, count) { + var counts = this.state.unreadCounts; + counts[index] = count; + this.setState({ + unreadCounts: counts }); }, visibleStyle: function(visible) { @@ -38,19 +47,32 @@ var MainPage = React.createClass({ }; }, render: function() { - var tabs = this.props.teams.map(function(team, index) { - return (); - }); 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 views = this.props.teams.map(function(team, index) { - return () + var handleUnreadCountChange = function(count) { + thisObj.handleUnreadCountChange(index, count); + }; + return () }); return ( - + { views } @@ -60,6 +82,7 @@ var MainPage = React.createClass({ } }); + var MattermostView = React.createClass({ getInitialState: function() { return { @@ -135,6 +158,7 @@ var MattermostView = React.createClass({ } }); + var configFile = remote.getGlobal('config-file'); var config = settings.readFileSync(configFile);