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

76 lines
2.2 KiB
JavaScript
Raw Normal View History

2015-12-28 23:34:32 +00:00
import React, { Component } from 'react';
import pure from 'pure-render-decorator';
import TabListItem from './TabListItem';
@pure
export default class TabList extends Component {
2015-12-30 21:32:14 +00:00
handleTabClick = (server, channel, pm) => {
const { select, hideMenu } = this.props;
select(server, channel, pm);
hideMenu();
}
2015-12-28 23:34:32 +00:00
handleConnectClick = () => {
this.props.pushPath('/connect');
this.props.hideMenu();
}
handleSettingsClick = () => {
this.props.pushPath('/settings');
this.props.hideMenu();
}
render() {
2015-12-30 21:32:14 +00:00
const { channels, servers, privateChats, showMenu, selected } = this.props;
2015-12-28 23:34:32 +00:00
const className = showMenu ? 'tablist off-canvas' : 'tablist';
const tabs = [];
channels.forEach((server, address) => {
tabs.push(
<TabListItem
key={address}
server
content={servers.getIn([address, 'name'])}
selected={selected.server === address && selected.channel === null && selected.user === null}
2015-12-30 21:32:14 +00:00
onClick={() => this.handleTabClick(address)}
2015-12-28 23:34:32 +00:00
/>
);
server.forEach((channel, name) => {
tabs.push(
<TabListItem
key={address + channel.get('name')}
content={channel.get('name')}
selected={selected.server === address && selected.channel === name}
2015-12-30 21:32:14 +00:00
onClick={() => this.handleTabClick(address, channel.get('name'))}
2015-12-28 23:34:32 +00:00
/>
);
});
if (privateChats.has(address)) {
privateChats.get(address).forEach(nick => {
tabs.push(
<TabListItem
key={address + nick}
content={nick}
selected={selected.server === address && selected.user === nick}
2015-12-30 21:32:14 +00:00
onClick={() => this.handleTabClick(address, nick, true)}
2015-12-28 23:34:32 +00:00
/>
);
});
}
});
return (
<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>
<i className="icon-cog" onClick={this.handleSettingsClick}></i>
</div>
</div>
);
}
}