gamja/components/buffer-list.js
Simon Ser 6c93bd13d1
Sort buffers when inserting, not when rendering
This allows all state.buffers users to iterate over the list in the
correct order.
2020-08-03 15:43:20 +02:00

38 lines
926 B
JavaScript

import { html, Component } from "/lib/index.js";
import { BufferType, Unread, getBufferURL } from "/state.js";
function BufferItem(props) {
function handleClick(event) {
event.preventDefault();
props.onClick();
}
var name = props.buffer.name;
if (props.buffer.type == BufferType.SERVER) {
name = "server";
}
var activeClass = props.active ? "active" : "";
var unreadClass = "";
if (props.buffer.unread != Unread.NONE) {
unreadClass = "unread-" + props.buffer.unread;
}
return html`
<li class="${activeClass} ${unreadClass}">
<a href=${getBufferURL(props.buffer)} onClick=${handleClick}>${name}</a>
</li>
`;
}
export default function BufferList(props) {
return html`
<ul>
${Array.from(props.buffers.values()).map((buf) => html`
<${BufferItem} key=${buf.name} buffer=${buf} onClick=${() => props.onBufferClick(buf.name)} active=${props.activeBuffer == buf.name}/>
`)}
</ul>
`;
}