dispatch/client/src/js/components/TabList.jsx

82 lines
1.9 KiB
React
Raw Normal View History

2015-01-17 01:37:21 +00:00
var React = require('react');
var Reflux = require('reflux');
var TabListItem = require('./TabListItem.jsx');
var channelStore = require('../stores/channel');
2015-01-30 01:34:28 +00:00
var privateChatStore = require('../stores/privateChat');
var serverStore = require('../stores/server');
var routeActions = require('../actions/route');
2015-06-09 22:59:41 +00:00
var tabActions = require('../actions/tab');
2015-05-20 06:14:44 +00:00
var PureMixin = require('../mixins/pure');
2015-01-17 01:37:21 +00:00
var TabList = React.createClass({
mixins: [
2015-05-20 06:14:44 +00:00
PureMixin,
Reflux.connect(serverStore, 'servers'),
2015-01-17 01:37:21 +00:00
Reflux.connect(channelStore, 'channels'),
Reflux.connect(privateChatStore, 'privateChats')
2015-01-17 01:37:21 +00:00
],
handleConnectClick() {
routeActions.navigate('connect');
2015-06-09 22:59:41 +00:00
tabActions.hideMenu();
},
handleSettingsClick() {
routeActions.navigate('settings');
2015-06-09 22:59:41 +00:00
tabActions.hideMenu();
},
render() {
2015-06-09 22:24:14 +00:00
var className = this.props.menuToggled ? 'tablist off-canvas' : 'tablist';
2015-05-20 06:14:44 +00:00
var tabs = [];
2015-01-30 01:34:28 +00:00
2015-05-20 06:14:44 +00:00
this.state.channels.forEach((server, address) => {
tabs.push(
2015-06-01 22:09:28 +00:00
<TabListItem
2015-05-20 06:14:44 +00:00
key={address}
2015-06-01 22:09:28 +00:00
server={address}
channel={null}
2015-05-20 06:14:44 +00:00
name={this.state.servers.getIn([address, 'name'])}>
</TabListItem>
);
2015-05-20 06:14:44 +00:00
server.forEach((channel, name) => {
tabs.push(
<TabListItem
2015-06-01 22:09:28 +00:00
key={address + name}
server={address}
2015-05-20 06:14:44 +00:00
channel={name}
name={name}>
</TabListItem>
);
});
if (this.state.privateChats.has(address)) {
this.state.privateChats.get(address).forEach(nick => {
tabs.push(
2015-06-01 22:09:28 +00:00
<TabListItem
2015-05-20 06:14:44 +00:00
key={address + nick}
2015-06-01 22:09:28 +00:00
server={address}
2015-05-20 06:14:44 +00:00
channel={nick}
name={nick}>
</TabListItem>
);
});
}
2015-01-17 01:37:21 +00:00
});
return (
2015-06-09 22:24:14 +00:00
<div className={className}>
<button className="button-connect" onClick={this.handleConnectClick}>Connect</button>
<div className="tab-container">{tabs}</div>
<div className="side-buttons">
<i className="icon-user"></i>
2015-02-16 20:53:01 +00:00
<i className="icon-cog" onClick={this.handleSettingsClick}></i>
</div>
</div>
2015-01-17 01:37:21 +00:00
);
}
});
module.exports = TabList;