Oh man that's a lot of changes.
This commit is contained in:
@@ -27,7 +27,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
inputContainer.style.display = "flex";
|
||||
|
||||
const defaultName = "Anon";
|
||||
const MAX_NAME_LEN = 31;
|
||||
const MAX_NAME_LEN = 15; // server limit is NAME_MAX_LENGTH-1 (15 chars)
|
||||
|
||||
const { socket, sendMessage, sendName } = initWebSocket(
|
||||
defaultName,
|
||||
@@ -88,8 +88,8 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
chat.addEventListener("click", (e) => {
|
||||
const msgDiv = e.target.closest(".msg");
|
||||
if (!msgDiv) return;
|
||||
const id = Number(msgDiv.dataset.id);
|
||||
if (!isFinite(id)) return;
|
||||
const id = msgDiv.dataset.id;
|
||||
if (!id) return;
|
||||
const threads = getThreads();
|
||||
const author = threads.get(id)?.username;
|
||||
setReplyTo(id);
|
||||
@@ -124,9 +124,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
if (e.key === "ArrowDown" || e.key === "ArrowUp") {
|
||||
const msgs = Array.from(chat.querySelectorAll("div.msg"));
|
||||
if (!msgs.length) return;
|
||||
let idx = msgs.findIndex(
|
||||
(div) => Number(div.dataset.id) === getFocused(),
|
||||
);
|
||||
let idx = msgs.findIndex((div) => div.dataset.id === getFocused());
|
||||
if (idx === -1) {
|
||||
idx = e.key === "ArrowDown" ? -1 : msgs.length;
|
||||
}
|
||||
@@ -134,7 +132,7 @@ document.addEventListener("DOMContentLoaded", () => {
|
||||
e.key === "ArrowDown"
|
||||
? Math.min(msgs.length - 1, idx + 1)
|
||||
: Math.max(0, idx - 1);
|
||||
const newId = Number(msgs[idx].dataset.id);
|
||||
const newId = msgs[idx].dataset.id;
|
||||
setFocused(newId);
|
||||
setReplyTo(newId); // Move input box under focused message.
|
||||
const threads = getThreads();
|
||||
|
||||
Reference in New Issue
Block a user