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

78 lines
2.2 KiB
JavaScript
Raw Normal View History

import React, { PureComponent } from 'react';
2015-12-28 23:34:32 +00:00
import TabListItem from './TabListItem';
export default class TabList extends PureComponent {
handleTabClick = (server, target) => this.props.select(server, target);
handleConnectClick = () => this.props.push('/connect');
handleSettingsClick = () => this.props.push('/settings');
2015-12-28 23:34:32 +00:00
render() {
const { tab, channels, servers, privateChats, showTabList } = this.props;
2016-01-11 22:31:06 +00:00
const className = showTabList ? 'tablist off-canvas' : 'tablist';
2015-12-28 23:34:32 +00:00
const tabs = [];
channels.forEach((server, address) => {
const srv = servers.get(address);
2015-12-28 23:34:32 +00:00
tabs.push(
<TabListItem
key={address}
2016-01-05 18:29:22 +00:00
server={address}
content={srv.name}
selected={tab.server === address && tab.name === null}
connected={srv.status.connected}
2016-01-05 18:29:22 +00:00
onClick={this.handleTabClick}
2015-12-28 23:34:32 +00:00
/>
);
2018-04-05 23:46:22 +00:00
server.forEach((channel, name) =>
tabs.push(
2016-01-05 18:29:22 +00:00
<TabListItem
2018-04-05 23:46:22 +00:00
key={address + name}
2016-01-05 18:29:22 +00:00
server={address}
2018-04-05 23:46:22 +00:00
target={name}
content={name}
selected={tab.server === address && tab.name === name}
2016-01-05 18:29:22 +00:00
onClick={this.handleTabClick}
/>
2018-04-05 23:46:22 +00:00
)
);
if (privateChats.has(address) && privateChats.get(address).size > 0) {
tabs.push(
<div key={`${address}-pm}`} className="tab-label">
Private messages
</div>
);
privateChats
.get(address)
.forEach(nick =>
tabs.push(
<TabListItem
key={address + nick}
server={address}
target={nick}
content={nick}
selected={tab.server === address && tab.name === nick}
onClick={this.handleTabClick}
/>
)
);
2015-12-28 23:34:32 +00:00
}
});
return (
<div className={className}>
2018-04-05 23:46:22 +00:00
<button className="button-connect" onClick={this.handleConnectClick}>
Connect
</button>
2015-12-28 23:34:32 +00:00
<div className="tab-container">{tabs}</div>
<div className="side-buttons">
2017-02-16 02:55:50 +00:00
<i className="icon-user" />
<i className="icon-cog" onClick={this.handleSettingsClick} />
2015-12-28 23:34:32 +00:00
</div>
</div>
);
}
}