2020-06-18 08:23:08 -04:00
|
|
|
import { html, Component } from "/lib/index.js";
|
2020-06-26 04:35:38 -04:00
|
|
|
import { BufferType, 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-26 04:35:38 -04:00
|
|
|
if (props.buffer.type == BufferType.SERVER) {
|
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-26 05:07:01 -04:00
|
|
|
var url = "#";
|
|
|
|
switch (props.buffer.type) {
|
|
|
|
case BufferType.SERVER:
|
|
|
|
url = "irc:///";
|
|
|
|
break;
|
|
|
|
case BufferType.CHANNEL:
|
|
|
|
url = "irc:///" + encodeURIComponent(props.buffer.name);
|
|
|
|
break;
|
|
|
|
case BufferType.NICK:
|
|
|
|
url = "irc:///" + encodeURIComponent(props.buffer.name) + ",isnick";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
return html`
|
2020-06-24 10:56:28 -04:00
|
|
|
<li class="${activeClass} ${unreadClass}">
|
2020-06-26 05:07:01 -04:00
|
|
|
<a href=${url} onClick=${handleClick}>${name}</a>
|
2020-06-18 08:23:08 -04:00
|
|
|
</li>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:40:27 -04:00
|
|
|
function compareBuffers(a, b) {
|
|
|
|
if (a.type == BufferType.SERVER) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (b.type == BufferType.SERVER) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (a.name > b.name) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
if (a.name < b.name) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
export default function BufferList(props) {
|
|
|
|
return html`
|
2020-06-26 09:16:07 -04:00
|
|
|
<ul>
|
2020-06-26 08:40:27 -04:00
|
|
|
${Array.from(this.props.buffers.values()).sort(compareBuffers).map(buf => html`
|
2020-06-26 08:41:03 -04:00
|
|
|
<${BufferItem} key=${buf.name} buffer=${buf} onClick=${() => props.onBufferClick(buf.name)} active=${props.activeBuffer == buf.name}/>
|
2020-06-18 08:23:08 -04:00
|
|
|
`)}
|
|
|
|
</ul>
|
|
|
|
`;
|
|
|
|
}
|