mirror of
https://codeberg.org/emersion/gamja.git
synced 2024-11-25 08:48:09 -05:00
6c93bd13d1
This allows all state.buffers users to iterate over the list in the correct order.
38 lines
926 B
JavaScript
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>
|
|
`;
|
|
}
|