2020-06-18 08:23:08 -04:00
|
|
|
import { html, Component } from "/lib/index.js";
|
2020-06-24 10:56:28 -04:00
|
|
|
import { SERVER_BUFFER, Unread } from "/state.js";
|
2020-06-18 08:23:08 -04:00
|
|
|
|
|
|
|
function BufferItem(props) {
|
|
|
|
function handleClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
props.onClick();
|
|
|
|
}
|
|
|
|
|
|
|
|
var name = props.buffer.name;
|
2020-06-24 10:56:28 -04:00
|
|
|
if (name == SERVER_BUFFER) {
|
2020-06-18 08:23:08 -04:00
|
|
|
name = "server";
|
|
|
|
}
|
|
|
|
|
2020-06-24 10:56:28 -04:00
|
|
|
var activeClass = props.active ? "active" : "";
|
|
|
|
|
|
|
|
var unreadClass = "";
|
|
|
|
if (props.buffer.unread != Unread.NONE) {
|
|
|
|
unreadClass = "unread-" + props.buffer.unread;
|
|
|
|
}
|
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
return html`
|
2020-06-24 10:56:28 -04:00
|
|
|
<li class="${activeClass} ${unreadClass}">
|
2020-06-18 08:23:08 -04:00
|
|
|
<a href="#" onClick=${handleClick}>${name}</a>
|
|
|
|
</li>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function BufferList(props) {
|
|
|
|
return html`
|
|
|
|
<ul id="buffer-list">
|
|
|
|
${Array.from(this.props.buffers.values()).map(buf => html`
|
|
|
|
<${BufferItem} buffer=${buf} onClick=${() => props.onBufferClick(buf.name)} active=${props.activeBuffer == buf.name}/>
|
|
|
|
`)}
|
|
|
|
</ul>
|
|
|
|
`;
|
|
|
|
}
|