2015-01-17 01:37:21 +00:00
|
|
|
var React = require('react');
|
|
|
|
var Reflux = require('reflux');
|
|
|
|
var _ = require('lodash');
|
|
|
|
|
2015-01-21 23:32:32 +00:00
|
|
|
var channelStore = require('../stores/channel');
|
2015-01-30 01:34:28 +00:00
|
|
|
var privateChatStore = require('../stores/privateChat');
|
2015-02-02 00:54:26 +00:00
|
|
|
var serverStore = require('../stores/server');
|
2015-01-21 23:32:32 +00:00
|
|
|
var selectedTabStore = require('../stores/selectedTab');
|
|
|
|
var tabActions = require('../actions/tab');
|
2015-01-17 01:37:21 +00:00
|
|
|
|
|
|
|
var TabList = React.createClass({
|
|
|
|
mixins: [
|
|
|
|
Reflux.connect(channelStore, 'channels'),
|
2015-01-30 01:34:28 +00:00
|
|
|
Reflux.connect(privateChatStore, 'privateChats'),
|
2015-02-02 00:54:26 +00:00
|
|
|
Reflux.connect(selectedTabStore, 'selectedTab'),
|
|
|
|
Reflux.connect(serverStore, 'servers')
|
2015-01-17 01:37:21 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
getInitialState: function() {
|
|
|
|
return {
|
|
|
|
channels: channelStore.getState(),
|
2015-01-30 01:34:28 +00:00
|
|
|
privateChats: privateChatStore.getState(),
|
2015-02-02 00:54:26 +00:00
|
|
|
selectedTab: selectedTabStore.getState(),
|
|
|
|
servers: serverStore.getState()
|
2015-01-17 01:37:21 +00:00
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
render: function() {
|
|
|
|
var self = this;
|
2015-01-29 23:38:51 +00:00
|
|
|
var tabClass;
|
|
|
|
var selected = this.state.selectedTab;
|
|
|
|
|
2015-01-17 01:37:21 +00:00
|
|
|
var tabs = _.map(this.state.channels, function(server, address) {
|
2015-01-29 23:38:51 +00:00
|
|
|
var channels = _.map(server, function(channel, name) {
|
|
|
|
if (address === selected.server &&
|
|
|
|
name === selected.channel) {
|
|
|
|
tabClass = 'selected';
|
|
|
|
} else {
|
|
|
|
tabClass = '';
|
|
|
|
}
|
|
|
|
|
2015-02-02 00:54:26 +00:00
|
|
|
return (
|
|
|
|
<p
|
|
|
|
className={tabClass}
|
|
|
|
onClick={tabActions.select.bind(null, address, name)}>
|
|
|
|
{name}
|
|
|
|
</p>
|
|
|
|
);
|
2015-01-17 01:37:21 +00:00
|
|
|
});
|
2015-01-29 23:38:51 +00:00
|
|
|
|
2015-01-30 01:34:28 +00:00
|
|
|
_.each(self.state.privateChats[address], function(chat, nick) {
|
|
|
|
if (address === selected.server &&
|
|
|
|
nick === selected.channel) {
|
|
|
|
tabClass = 'selected';
|
|
|
|
} else {
|
|
|
|
tabClass = '';
|
|
|
|
}
|
2015-02-02 00:54:26 +00:00
|
|
|
|
|
|
|
channels.push(
|
|
|
|
<p
|
|
|
|
className={tabClass}
|
|
|
|
onClick={tabActions.select.bind(null, address, nick)}>
|
|
|
|
{nick}
|
|
|
|
</p>
|
|
|
|
);
|
2015-01-30 01:34:28 +00:00
|
|
|
});
|
|
|
|
|
2015-01-29 23:38:51 +00:00
|
|
|
if (address === selected.server &&
|
|
|
|
selected.channel === null) {
|
|
|
|
tabClass = 'tab-server selected';
|
|
|
|
} else {
|
|
|
|
tabClass = 'tab-server';
|
|
|
|
}
|
|
|
|
|
2015-02-02 00:54:26 +00:00
|
|
|
channels.unshift(
|
|
|
|
<p
|
|
|
|
className={tabClass}
|
|
|
|
onClick={tabActions.select.bind(null, address, null)}>
|
|
|
|
{serverStore.getName(address)}
|
|
|
|
</p>
|
|
|
|
);
|
2015-01-29 23:38:51 +00:00
|
|
|
|
2015-01-17 01:37:21 +00:00
|
|
|
return channels;
|
|
|
|
});
|
|
|
|
|
|
|
|
return (
|
2015-01-29 23:38:51 +00:00
|
|
|
<div className="tablist">
|
|
|
|
<button className="button-connect">Add Network</button>
|
|
|
|
{tabs}
|
|
|
|
<div className="side-buttons">
|
|
|
|
<button>Settings</button>
|
|
|
|
</div>
|
|
|
|
</div>
|
2015-01-17 01:37:21 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = TabList;
|