Spaces:
Sleeping
Sleeping
resolve continuous chat error"
Browse files- static/script.js +27 -4
- static/styles.css +1 -1
- templates/chat.html +1 -5
static/script.js
CHANGED
@@ -6,15 +6,34 @@ const sendButton = document.getElementById('send-button');
|
|
6 |
var converter = new showdown.Converter();
|
7 |
var response="";
|
8 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
function appendMessage(message, sender) {
|
10 |
if(sender == "bot"){
|
11 |
response += message;
|
12 |
message = converter.makeHtml(response);
|
13 |
|
14 |
-
loader_ele =
|
15 |
|
16 |
if(!loader_ele.classList.contains("hidden")){
|
17 |
-
|
18 |
const messageElement = document.createElement('div');
|
19 |
messageElement.classList.add('chat-message', sender);
|
20 |
messageElement.innerHTML = `<span>${message}</span>`;
|
@@ -23,15 +42,16 @@ function appendMessage(message, sender) {
|
|
23 |
}else{
|
24 |
last_message_ele = chatBox.lastElementChild.lastChild;
|
25 |
last_message_ele.innerHTML = message;
|
|
|
26 |
}
|
27 |
}else{
|
28 |
const messageElement = document.createElement('div');
|
29 |
messageElement.classList.add('chat-message', sender);
|
30 |
messageElement.innerHTML = `<span>${message}</span>`;
|
31 |
-
chatBox.
|
32 |
chatBox.scrollTop = chatBox.scrollHeight;
|
33 |
setTimeout(() => {
|
34 |
-
|
35 |
}, 500);
|
36 |
}
|
37 |
chatBox.scrollTop = chatBox.scrollHeight;
|
@@ -42,6 +62,9 @@ sendButton.addEventListener('click', () => {
|
|
42 |
if (message) {
|
43 |
appendMessage(message, 'user');
|
44 |
socket.emit('message', { question: message, session_id: 'abc123' });
|
|
|
|
|
|
|
45 |
chatInput.value = '';
|
46 |
response = "";
|
47 |
}
|
|
|
6 |
var converter = new showdown.Converter();
|
7 |
var response="";
|
8 |
|
9 |
+
|
10 |
+
function addLoader(){
|
11 |
+
// loader_ele = `
|
12 |
+
// <div class="dot-loader">
|
13 |
+
// <div></div>
|
14 |
+
// <div></div>
|
15 |
+
// <div></div>
|
16 |
+
// </div>
|
17 |
+
// `
|
18 |
+
const loader_ele = document.createElement('div');
|
19 |
+
loader_ele.classList.add('dot-loader');
|
20 |
+
loader_ele.innerHTML = `
|
21 |
+
<div></div>
|
22 |
+
<div></div>
|
23 |
+
<div></div>
|
24 |
+
`;
|
25 |
+
chatBox.appendChild(loader_ele);
|
26 |
+
}
|
27 |
+
|
28 |
function appendMessage(message, sender) {
|
29 |
if(sender == "bot"){
|
30 |
response += message;
|
31 |
message = converter.makeHtml(response);
|
32 |
|
33 |
+
let loader_ele = chatBox.lastElementChild;
|
34 |
|
35 |
if(!loader_ele.classList.contains("hidden")){
|
36 |
+
chatBox.removeChild(loader_ele);
|
37 |
const messageElement = document.createElement('div');
|
38 |
messageElement.classList.add('chat-message', sender);
|
39 |
messageElement.innerHTML = `<span>${message}</span>`;
|
|
|
42 |
}else{
|
43 |
last_message_ele = chatBox.lastElementChild.lastChild;
|
44 |
last_message_ele.innerHTML = message;
|
45 |
+
chatBox.scrollTop = chatBox.scrollHeight;
|
46 |
}
|
47 |
}else{
|
48 |
const messageElement = document.createElement('div');
|
49 |
messageElement.classList.add('chat-message', sender);
|
50 |
messageElement.innerHTML = `<span>${message}</span>`;
|
51 |
+
chatBox.append(messageElement);
|
52 |
chatBox.scrollTop = chatBox.scrollHeight;
|
53 |
setTimeout(() => {
|
54 |
+
addLoader()
|
55 |
}, 500);
|
56 |
}
|
57 |
chatBox.scrollTop = chatBox.scrollHeight;
|
|
|
62 |
if (message) {
|
63 |
appendMessage(message, 'user');
|
64 |
socket.emit('message', { question: message, session_id: 'abc123' });
|
65 |
+
// setInterval(()=>{
|
66 |
+
// appendMessage("This is a test message", "bot");
|
67 |
+
// }, 2000)
|
68 |
chatInput.value = '';
|
69 |
response = "";
|
70 |
}
|
static/styles.css
CHANGED
@@ -91,7 +91,7 @@ body {
|
|
91 |
background-color: #e0e0e0;
|
92 |
color: #333;
|
93 |
padding: 15px;
|
94 |
-
border-radius:
|
95 |
width: fit-content;
|
96 |
display: flex;
|
97 |
justify-content: center;
|
|
|
91 |
background-color: #e0e0e0;
|
92 |
color: #333;
|
93 |
padding: 15px;
|
94 |
+
border-radius: 10px;
|
95 |
width: fit-content;
|
96 |
display: flex;
|
97 |
justify-content: center;
|
templates/chat.html
CHANGED
@@ -12,11 +12,7 @@
|
|
12 |
<div class="chat-box" id="chat-box">
|
13 |
|
14 |
|
15 |
-
|
16 |
-
<div></div>
|
17 |
-
<div></div>
|
18 |
-
<div></div>
|
19 |
-
</div>
|
20 |
</div>
|
21 |
<div class="input-container">
|
22 |
<input type="text" id="chat-input" placeholder="Type your message here...">
|
|
|
12 |
<div class="chat-box" id="chat-box">
|
13 |
|
14 |
|
15 |
+
|
|
|
|
|
|
|
|
|
16 |
</div>
|
17 |
<div class="input-container">
|
18 |
<input type="text" id="chat-input" placeholder="Type your message here...">
|