Print current connection status

This commit is contained in:
Simon Ser 2021-01-22 11:53:17 +01:00
parent 51523f4014
commit e6592d7d8b
2 changed files with 22 additions and 13 deletions

View File

@ -1001,7 +1001,7 @@ export default class App extends Component {
if (activeBuffer) {
bufferHeader = html`
<section id="buffer-header">
<${BufferHeader} buffer=${activeBuffer} onClose=${() => this.close(activeBuffer)}/>
<${BufferHeader} buffer=${activeBuffer} network=${activeNetwork} onClose=${() => this.close(activeBuffer)}/>
</section>
`;
}

View File

@ -1,9 +1,9 @@
import { html, Component } from "/lib/index.js";
import linkify from "/lib/linkify.js";
import { strip as stripANSI } from "/lib/ansi.js";
import { BufferType } from "/state.js";
import { BufferType, Status } from "/state.js";
const Status = {
const UserStatus = {
HERE: "here",
GONE: "gone",
OFFLINE: "offline",
@ -11,9 +11,9 @@ const Status = {
function NickStatus(props) {
var textMap = {
[Status.HERE]: "User is online",
[Status.GONE]: "User is away",
[Status.OFFLINE]: "User is offline",
[UserStatus.HERE]: "User is online",
[UserStatus.GONE]: "User is away",
[UserStatus.OFFLINE]: "User is offline",
};
var text = textMap[props.status];
return html`<span class="status status-${props.status}" title=${text}>●</span>`;
@ -27,9 +27,18 @@ export default function BufferHeader(props) {
var description = null;
if (props.buffer.serverInfo) {
// TODO: print current connection status
var serverInfo = props.buffer.serverInfo;
description = `Connected to ${serverInfo.name}`;
switch (props.network.status) {
case Status.DISCONNECTED:
description = "Disconnected";
break;
case Status.CONNECTING:
description = "Connecting...";
break;
case Status.REGISTERED:
var serverInfo = props.buffer.serverInfo;
description = `Connected to ${serverInfo.name}`;
break;
}
} else if (props.buffer.topic) {
description = linkify(stripANSI(props.buffer.topic));
} else if (props.buffer.who) {
@ -37,18 +46,18 @@ export default function BufferHeader(props) {
var realname = stripANSI(who.realname || "");
var status = Status.HERE;
var status = UserStatus.HERE;
if (who.away) {
status = Status.GONE;
status = UserStatus.GONE;
}
if (props.buffer.offline) {
status = Status.OFFLINE;
status = UserStatus.OFFLINE;
}
description = html`<${NickStatus} status=${status}/> ${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}`;
description = html`<${NickStatus} status=${UserStatus.OFFLINE}/> ${props.buffer.name}`;
}
var closeText = "Close";