gamja-old/components/buffer-list.js

66 lines
1.5 KiB
JavaScript
Raw Normal View History

import * as irc from "../lib/irc.js";
import { html, Component } from "../lib/index.js";
import { BufferType, Unread, getBufferURL, getServerName } from "../state.js";
2021-01-22 05:43:47 -05:00
function BufferItem(props) {
function handleClick(event) {
event.preventDefault();
props.onClick();
}
2021-10-17 13:33:02 -04:00
function handleMouseDown(event) {
if (event.button === 1) { // middle click
event.preventDefault();
props.onClose();
}
}
2021-06-10 12:11:11 -04:00
let name = props.buffer.name;
2020-06-26 04:35:38 -04:00
if (props.buffer.type == BufferType.SERVER) {
name = getServerName(props.server, props.bouncerNetwork);
}
2021-06-10 12:11:11 -04:00
let classes = ["type-" + props.buffer.type];
if (props.active) {
classes.push("active");
}
2020-06-24 10:56:28 -04:00
if (props.buffer.unread != Unread.NONE) {
classes.push("unread-" + props.buffer.unread);
2020-06-24 10:56:28 -04:00
}
return html`
<li class="${classes.join(" ")}">
2021-10-17 13:33:02 -04:00
<a
href=${getBufferURL(props.buffer)}
onClick=${handleClick}
onMouseDown=${handleMouseDown}
>${name}</a>
</li>
`;
}
2020-06-26 08:40:27 -04:00
export default function BufferList(props) {
2021-06-10 12:11:11 -04:00
let items = Array.from(props.buffers.values()).map((buf) => {
let server = props.servers.get(buf.server);
2021-06-10 12:11:11 -04:00
let bouncerNetwork = null;
if (server.bouncerNetID) {
bouncerNetwork = props.bouncerNetworks.get(server.bouncerNetID);
}
return html`
2021-05-31 11:34:36 -04:00
<${BufferItem}
key=${buf.id}
buffer=${buf}
server=${server}
2021-05-31 11:34:36 -04:00
bouncerNetwork=${bouncerNetwork}
onClick=${() => props.onBufferClick(buf)}
2021-10-17 13:33:02 -04:00
onClose=${() => props.onBufferClose(buf)}
2021-05-31 11:34:36 -04:00
active=${props.activeBuffer == buf.id}
/>
`;
});
return html`<ul>${items}</ul>`;
}