2021-03-02 16:46:48 -05:00
|
|
|
import * as irc from "../lib/irc.js";
|
|
|
|
import { html, Component } from "../lib/index.js";
|
2021-06-03 05:46:50 -04:00
|
|
|
import { BufferType, Unread, getBufferURL, getServerName } from "../state.js";
|
2021-01-22 05:43:47 -05:00
|
|
|
|
2020-06-18 08:23:08 -04: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();
|
|
|
|
}
|
|
|
|
}
|
2020-06-18 08:23:08 -04:00
|
|
|
|
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) {
|
2021-06-03 05:46:50 -04:00
|
|
|
name = getServerName(props.server, props.bouncerNetwork, props.isBouncer);
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let classes = ["type-" + props.buffer.type];
|
2021-01-23 06:04:58 -05:00
|
|
|
if (props.active) {
|
|
|
|
classes.push("active");
|
|
|
|
}
|
2020-06-24 10:56:28 -04:00
|
|
|
if (props.buffer.unread != Unread.NONE) {
|
2021-01-23 06:04:58 -05:00
|
|
|
classes.push("unread-" + props.buffer.unread);
|
2020-06-24 10:56:28 -04:00
|
|
|
}
|
|
|
|
|
2020-06-18 08:23:08 -04:00
|
|
|
return html`
|
2021-01-23 06:04:58 -05:00
|
|
|
<li class="${classes.join(" ")}">
|
2021-10-17 13:33:02 -04:00
|
|
|
<a
|
|
|
|
href=${getBufferURL(props.buffer)}
|
|
|
|
onClick=${handleClick}
|
|
|
|
onMouseDown=${handleMouseDown}
|
|
|
|
>${name}</a>
|
2020-06-18 08:23:08 -04:00
|
|
|
</li>
|
|
|
|
`;
|
|
|
|
}
|
|
|
|
|
2020-06-26 08:40:27 -04:00
|
|
|
|
2020-06-18 08:23:08 -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-01-22 15:01:03 -05:00
|
|
|
|
2021-06-10 12:11:11 -04:00
|
|
|
let bouncerNetwork = null;
|
|
|
|
let bouncerNetID = server.isupport.get("BOUNCER_NETID");
|
2021-01-22 15:01:03 -05:00
|
|
|
if (bouncerNetID) {
|
|
|
|
bouncerNetwork = props.bouncerNetworks.get(bouncerNetID);
|
|
|
|
}
|
|
|
|
|
|
|
|
return html`
|
2021-05-31 11:34:36 -04:00
|
|
|
<${BufferItem}
|
|
|
|
key=${buf.id}
|
|
|
|
buffer=${buf}
|
2021-06-03 05:46:50 -04:00
|
|
|
server=${server}
|
2021-05-31 11:34:36 -04:00
|
|
|
isBouncer=${props.isBouncer}
|
|
|
|
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}
|
|
|
|
/>
|
2021-01-22 15:01:03 -05:00
|
|
|
`;
|
|
|
|
});
|
|
|
|
|
|
|
|
return html`<ul>${items}</ul>`;
|
2020-06-18 08:23:08 -04:00
|
|
|
}
|