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) { if (activeBuffer) {
bufferHeader = html` bufferHeader = html`
<section id="buffer-header"> <section id="buffer-header">
<${BufferHeader} buffer=${activeBuffer} onClose=${() => this.close(activeBuffer)}/> <${BufferHeader} buffer=${activeBuffer} network=${activeNetwork} onClose=${() => this.close(activeBuffer)}/>
</section> </section>
`; `;
} }

View File

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