Skip to content

Commit

Permalink
improve log style
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderKolberg committed Dec 8, 2023
1 parent b12bf03 commit 9d4aa13
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 5 deletions.
13 changes: 9 additions & 4 deletions _examples/golang-sse/webapp/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Message[]>([]);

const log = signal<string[]>([]);
type Log = { type: "error" | "info" | "warn"; log: string };
const log = signal<Log[]>([]);

//Create message handlers
const onMessage = (message: SubscribeMessagesReturn) => {
Expand All @@ -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();
Expand Down Expand Up @@ -94,7 +97,9 @@ const logEl = document.querySelector("#log");
effect(() => {
if (logEl) {
logEl.innerHTML = `
${log.value.map((log) => `<div>${log}</div>`).join("")}
${log.value
.map((log) => `<div class=${log.type}>${log.log}</div>`)
.join("")}
`;
logEl.scrollTo(0, logEl.scrollHeight);
}
Expand Down
17 changes: 16 additions & 1 deletion _examples/golang-sse/webapp/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
}

body {
height: 100vh;
margin: 0;
padding: 0;
font-family: "Open Sans", sans-serif;
Expand Down Expand Up @@ -43,6 +42,7 @@ header {
background: #e4eaee;
position: relative;
}

#log {
padding: 10px;
}
Expand Down Expand Up @@ -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;
}

0 comments on commit 9d4aa13

Please sign in to comment.