From a63702ef905191b80d721559d4cb740348ed7989 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 12 Mar 2021 12:27:57 +0100 Subject: [PATCH 1/2] web: add close button to messages --- web/src/elements/messages/Message.ts | 9 +++++++++ web/src/elements/router/RouterOutlet.ts | 5 ++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/web/src/elements/messages/Message.ts b/web/src/elements/messages/Message.ts index 50d3e3b78..55adf7ea9 100644 --- a/web/src/elements/messages/Message.ts +++ b/web/src/elements/messages/Message.ts @@ -46,6 +46,15 @@ export class Message extends LitElement {

${this.message?.message}

+
+ +
`; } diff --git a/web/src/elements/router/RouterOutlet.ts b/web/src/elements/router/RouterOutlet.ts index 796511c34..6aae6046e 100644 --- a/web/src/elements/router/RouterOutlet.ts +++ b/web/src/elements/router/RouterOutlet.ts @@ -50,18 +50,17 @@ export class RouterOutlet extends LitElement { if (activeUrl === "") { activeUrl = this.defaultUrl || "/"; window.location.hash = `#${activeUrl}`; - console.debug(`authentik/router: set to ${window.location.hash}`); + console.debug(`authentik/router: defaulted URL to ${window.location.hash}`); return; } let matchedRoute: RouteMatch | null = null; ROUTES.some((route) => { - console.debug(`authentik/router: matching ${activeUrl} against ${route.url}`); const match = route.url.exec(activeUrl); if (match != null) { matchedRoute = new RouteMatch(route); matchedRoute.arguments = match.groups || {}; matchedRoute.fullUrl = activeUrl; - console.debug(`authentik/router: found match ${matchedRoute}`); + console.debug("authentik/router: found match ", matchedRoute); return true; } }); From b63b789f7796d08ed7f598ef29d50443f9ff68fe Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 12 Mar 2021 12:41:17 +0100 Subject: [PATCH 2/2] web: prevent duplicate messages --- web/src/elements/messages/MessageContainer.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/web/src/elements/messages/MessageContainer.ts b/web/src/elements/messages/MessageContainer.ts index 394219dc7..3ed15286a 100644 --- a/web/src/elements/messages/MessageContainer.ts +++ b/web/src/elements/messages/MessageContainer.ts @@ -8,7 +8,7 @@ export function showMessage(message: APIMessage): void { if (!container) { throw new Error("failed to find message container"); } - container.messages.push(message); + container.addMessage(message); container.requestUpdate(); } @@ -34,6 +34,14 @@ export class MessageContainer extends LitElement { } } + // add a new message, but only if the message isn't currently shown. + addMessage(message: APIMessage): void { + const matchingMessages = this.messages.filter(m => m.message == message.message); + if (matchingMessages.length < 1) { + this.messages.push(message); + } + } + connect(): void { if (navigator.webdriver) return; const wsUrl = `${window.location.protocol.replace("http", "ws")}//${ @@ -60,7 +68,7 @@ export class MessageContainer extends LitElement { }); this.messageSocket.addEventListener("message", (e) => { const data = JSON.parse(e.data); - this.messages.push(data); + this.addMessage(data); this.requestUpdate(); }); this.messageSocket.addEventListener("error", (e) => { @@ -76,8 +84,8 @@ export class MessageContainer extends LitElement { .message=${m} .onRemove=${(m: APIMessage) => { this.messages = this.messages.filter((v) => v !== m); - this.requestUpdate(); - }}> + this.requestUpdate(); + }}> `; })} `;