From 9d4aa1315a1bbdaf4908105f3c12edeb582854f6 Mon Sep 17 00:00:00 2001 From: Alexander Kolberg Date: Fri, 8 Dec 2023 18:43:23 +0100 Subject: [PATCH] improve log style --- _examples/golang-sse/webapp/src/main.ts | 13 +++++++++---- _examples/golang-sse/webapp/src/style.css | 17 ++++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/_examples/golang-sse/webapp/src/main.ts b/_examples/golang-sse/webapp/src/main.ts index 475146b8..5463e902 100644 --- a/_examples/golang-sse/webapp/src/main.ts +++ b/_examples/golang-sse/webapp/src/main.ts @@ -5,10 +5,11 @@ import "./style.css"; //Create client const api = new Chat("http://localhost:4848", fetch); -//Create signal for messages +//Create signal for messages and log const messages = signal([]); -const log = signal([]); +type Log = { type: "error" | "info" | "warn"; log: string }; +const log = signal([]); //Create message handlers const onMessage = (message: SubscribeMessagesReturn) => { @@ -18,15 +19,17 @@ const onMessage = (message: SubscribeMessagesReturn) => { const onError = (error: WebrpcError) => { console.error("onError()", error); + log.value = [...log.value, { type: "error", log: String(error) }]; }; const onOpen = () => { console.log("onOpen()"); - log.value = [...log.value, "Connected"]; + log.value = [...log.value, { type: "info", log: "Connected" }]; }; const onClose = () => { console.log("onClose()"); + log.value = [...log.value, { type: "warn", log: "Disconnected" }]; }; const username = randomUserName(); @@ -94,7 +97,9 @@ const logEl = document.querySelector("#log"); effect(() => { if (logEl) { logEl.innerHTML = ` - ${log.value.map((log) => `
${log}
`).join("")} + ${log.value + .map((log) => `
${log.log}
`) + .join("")} `; logEl.scrollTo(0, logEl.scrollHeight); } diff --git a/_examples/golang-sse/webapp/src/style.css b/_examples/golang-sse/webapp/src/style.css index f517d622..2cb4d152 100644 --- a/_examples/golang-sse/webapp/src/style.css +++ b/_examples/golang-sse/webapp/src/style.css @@ -3,7 +3,6 @@ } body { - height: 100vh; margin: 0; padding: 0; font-family: "Open Sans", sans-serif; @@ -43,6 +42,7 @@ header { background: #e4eaee; position: relative; } + #log { padding: 10px; } @@ -118,3 +118,18 @@ button { padding: 10px; cursor: pointer; } + +#log > div { + padding-block: 7px; + border-bottom: 1px solid #cfdae1; +} + +.error { + color: red; +} +.info { + color: green; +} +.warn { + color: orange; +}