From 6b97b226e694aefa5c57ae731026c4038fc7134b Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Mon, 19 Oct 2020 20:23:28 +1300 Subject: [PATCH] Focus chat when switching room --- build/index.html | 4 ++-- build/static/chat-input.js | 25 ++++++++++++++++--------- build/static/chat.js | 2 +- build/static/store/SubscribeMapList.js | 1 - src/js/chat-input.js | 8 +++++++- src/js/chat.js | 2 +- 6 files changed, 27 insertions(+), 15 deletions(-) diff --git a/build/index.html b/build/index.html index a8f668f..a14a855 100644 --- a/build/index.html +++ b/build/index.html @@ -4,10 +4,10 @@ - + - + Carbon diff --git a/build/static/chat-input.js b/build/static/chat-input.js index a245c52..d8c0a35 100644 --- a/build/static/chat-input.js +++ b/build/static/chat-input.js @@ -1,29 +1,36 @@ import {q} from "./basic.js" import {store} from "./store/store.js" import * as lsm from "./lsm.js" +import {chat} from "./chat.js" let sentIndex = 0 -const chat = q("#c-chat-textarea") +const input = q("#c-chat-textarea") -chat.addEventListener("keydown", event => { +store.activeRoom.subscribe("changeSelf", () => { + if (store.activeRoom.exists()) { + input.focus() + } +}) + +input.addEventListener("keydown", event => { if (event.key === "Enter" && !event.shiftKey && !event.ctrlKey) { event.preventDefault() - const body = chat.value - send(chat.value) - chat.value = "" + const body = input.value + send(input.value) + input.value = "" fixHeight() } }) -chat.addEventListener("input", () => { +input.addEventListener("input", () => { fixHeight() }) function fixHeight() { - chat.style.height = "0px" - console.log(chat.clientHeight, chat.scrollHeight) - chat.style.height = (chat.scrollHeight + 1) + "px" + input.style.height = "0px" + // console.log(input.clientHeight, input.scrollHeight) + input.style.height = (input.scrollHeight + 1) + "px" } function getTxnId() { diff --git a/build/static/chat.js b/build/static/chat.js index 38c4684..9958dc3 100644 --- a/build/static/chat.js +++ b/build/static/chat.js @@ -34,7 +34,7 @@ class Chat extends ElemJS { let oldDifference = chatMessages.scrollHeight - chatMessages.clientHeight setTimeout(() => { let newDifference = chatMessages.scrollHeight - chatMessages.clientHeight - console.log("height difference", oldDifference, newDifference) + // console.log("height difference", oldDifference, newDifference) if (oldDifference < 24) { // this is jank this.element.parentElement.scrollBy(0, 1000) } diff --git a/build/static/store/SubscribeMapList.js b/build/static/store/SubscribeMapList.js index e5ae4ed..b26d58c 100644 --- a/build/static/store/SubscribeMapList.js +++ b/build/static/store/SubscribeMapList.js @@ -54,7 +54,6 @@ class SubscribeMapList extends Subscribable { } sort() { - console.log("sorting") this.list.sort((a, b) => { const orderA = this.map.get(a).value().order const orderB = this.map.get(b).value().order diff --git a/src/js/chat-input.js b/src/js/chat-input.js index e06db8a..d8c0a35 100644 --- a/src/js/chat-input.js +++ b/src/js/chat-input.js @@ -7,6 +7,12 @@ let sentIndex = 0 const input = q("#c-chat-textarea") +store.activeRoom.subscribe("changeSelf", () => { + if (store.activeRoom.exists()) { + input.focus() + } +}) + input.addEventListener("keydown", event => { if (event.key === "Enter" && !event.shiftKey && !event.ctrlKey) { event.preventDefault() @@ -23,7 +29,7 @@ input.addEventListener("input", () => { function fixHeight() { input.style.height = "0px" - console.log(input.clientHeight, input.scrollHeight) + // console.log(input.clientHeight, input.scrollHeight) input.style.height = (input.scrollHeight + 1) + "px" } diff --git a/src/js/chat.js b/src/js/chat.js index 38c4684..9958dc3 100644 --- a/src/js/chat.js +++ b/src/js/chat.js @@ -34,7 +34,7 @@ class Chat extends ElemJS { let oldDifference = chatMessages.scrollHeight - chatMessages.clientHeight setTimeout(() => { let newDifference = chatMessages.scrollHeight - chatMessages.clientHeight - console.log("height difference", oldDifference, newDifference) + // console.log("height difference", oldDifference, newDifference) if (oldDifference < 24) { // this is jank this.element.parentElement.scrollBy(0, 1000) }