2020-06-25 12:30:21 -04:00
|
|
|
import { html, Component } from "/lib/index.js";
|
2020-06-26 06:00:10 -04:00
|
|
|
import { BufferType } from "/state.js";
|
2020-06-25 12:30:21 -04:00
|
|
|
|
2020-07-13 06:51:09 -04:00
|
|
|
const Status = {
|
|
|
|
HERE: "here",
|
|
|
|
GONE: "gone",
|
|
|
|
OFFLINE: "offline",
|
|
|
|
};
|
|
|
|
|
|
|
|
function NickStatus(props) {
|
|
|
|
var textMap = {
|
|
|
|
[Status.HERE]: "User is online",
|
|
|
|
[Status.GONE]: "User is away",
|
|
|
|
[Status.OFFLINE]: "User is offline",
|
|
|
|
};
|
|
|
|
var text = textMap[props.status];
|
|
|
|
return html`<span class="status status-${props.status}" title=${text}>●</span>`;
|
|
|
|
}
|
|
|
|
|
2020-06-25 12:30:21 -04:00
|
|
|
export default function BufferHeader(props) {
|
|
|
|
function handlePartClick(event) {
|
|
|
|
event.preventDefault();
|
|
|
|
props.onClose();
|
|
|
|
}
|
|
|
|
|
2020-06-26 06:00:10 -04:00
|
|
|
var description = null;
|
2020-06-26 06:08:14 -04:00
|
|
|
if (props.buffer.serverInfo) {
|
|
|
|
var serverInfo = props.buffer.serverInfo;
|
|
|
|
description = `Connected to ${serverInfo.name}`;
|
|
|
|
} else if (props.buffer.topic) {
|
|
|
|
description = props.buffer.topic;
|
2020-06-26 06:00:10 -04:00
|
|
|
} else if (props.buffer.who) {
|
|
|
|
var who = props.buffer.who;
|
2020-06-26 06:45:27 -04:00
|
|
|
|
2020-07-13 06:51:09 -04:00
|
|
|
var status = Status.HERE;
|
2020-06-26 06:45:27 -04:00
|
|
|
if (who.away) {
|
2020-07-13 06:51:09 -04:00
|
|
|
status = Status.GONE;
|
|
|
|
}
|
|
|
|
if (props.buffer.offline) {
|
|
|
|
status = Status.OFFLINE;
|
2020-06-26 06:45:27 -04:00
|
|
|
}
|
|
|
|
|
2020-07-13 06:51:09 -04:00
|
|
|
description = html`<${NickStatus} status=${status}/> ${who.realname} (${who.username}@${who.hostname})`;
|
|
|
|
} else if (props.buffer.offline) {
|
|
|
|
// User is offline, but we don't have WHO information
|
|
|
|
description = html`<${NickStatus} status=${Status.OFFLINE}/> ${props.buffer.name}`;
|
2020-06-26 06:00:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
var closeText = "Close";
|
|
|
|
switch (props.buffer.type) {
|
|
|
|
case BufferType.SERVER:
|
|
|
|
closeText = "Disconnect";
|
|
|
|
break;
|
|
|
|
case BufferType.CHANNEL:
|
|
|
|
closeText = "Part";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2020-06-25 12:30:21 -04:00
|
|
|
return html`
|
2020-06-26 06:08:14 -04:00
|
|
|
<span class="description">${description}</span>
|
2020-06-25 12:30:21 -04:00
|
|
|
<span class="actions">
|
2020-06-26 06:00:10 -04:00
|
|
|
<a href="#" onClick=${handlePartClick}>${closeText}</a>
|
2020-06-25 12:30:21 -04:00
|
|
|
</span>
|
|
|
|
`;
|
|
|
|
}
|