From: mar77i <mar77i@protonmail.ch>
Date: Mon, 30 Sep 2024 21:52:35 +0000 (+0200)
Subject: disable textarea before any channel is selected
X-Git-Url: https://git.mar77i.info/?a=commitdiff_plain;h=fcd3d2e11863a0ba41d9f2167542b9693fd87dbe;p=chat

disable textarea before any channel is selected
---

diff --git a/chat/static/chat/chat.css b/chat/static/chat/chat.css
index 33d1121..271f979 100644
--- a/chat/static/chat/chat.css
+++ b/chat/static/chat/chat.css
@@ -39,4 +39,4 @@ nav > div {
 
 .input > textarea {
     resize: none;
-}
\ No newline at end of file
+}
diff --git a/chat/static/chat/chat.js b/chat/static/chat/chat.js
index 2712273..5d91720 100644
--- a/chat/static/chat/chat.js
+++ b/chat/static/chat/chat.js
@@ -181,6 +181,9 @@
         fetch_data(
             "/api/privatemessage/?other=" + user_id.toString(), add_privatemessages
         );
+        document.getElementsByClassName("input")[0].children[0].removeAttribute(
+            "disabled"
+        );
     }
 
     function setup_user_callback() {
@@ -248,6 +251,9 @@
         fetch_data(
             "/api/channelmessage/?channel=" + channel_id.toString(), add_channelmessages
         );
+        document.getElementsByClassName("input")[0].children[0].removeAttribute(
+            "disabled"
+        );
     }
 
     function setup_channel_callback() {
@@ -280,8 +286,10 @@
                 data[name] = current_channel.data[name];
             }
         }
-        post_data(current_channel.url, JSON.stringify(data), null);
-        ta.value = "";
+        if (current_channel.url) {
+            post_data(current_channel.url, JSON.stringify(data), null);
+            ta.value = "";
+        }
     }
 
     function input_onkeydown(event) {
@@ -301,13 +309,16 @@
         function (event) {
             var ws, schema, input;
             event = event || window.event;
+            input = document.getElementsByClassName("input")[0];
+            if (!current_channel.url) {
+                input.children[0].setAttribute("disabled", "");
+            }
             if (event.target.readyState !== "complete") {
                 return;
             }
             schema = {"http:": "ws:", "https:": "wss:"}[window.location.protocol];
             ws = new WebSocket(schema + "//" + window.location.host + "/");
             ws.addEventListener("message", ws_receive);
-            input = document.getElementsByClassName("input")[0];
             input.children[0].addEventListener("keydown", input_onkeydown);
             input.children[0].value = "";
             input.children[1].addEventListener("click", send);