Spaces:
Running
Running
Vedika commited on
Update index.html
Browse files- index.html +17 -5
index.html
CHANGED
|
@@ -640,7 +640,7 @@
|
|
| 640 |
<div id="chatMessages"></div>
|
| 641 |
</div>
|
| 642 |
|
| 643 |
-
<button id="scrollToBottomBtn" class="btn-scroll-bottom" onclick="UI.scrollToBottom(true)" title="Go to latest">
|
| 644 |
<svg style="width:20px;height:20px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
| 645 |
<line x1="12" y1="5" x2="12" y2="19"></line>
|
| 646 |
<polyline points="19 12 12 19 5 12"></polyline>
|
|
@@ -988,6 +988,7 @@
|
|
| 988 |
};
|
| 989 |
|
| 990 |
const UI = {
|
|
|
|
| 991 |
toggleSidebar() {
|
| 992 |
const sb = document.getElementById('sidebar');
|
| 993 |
const overlay = document.getElementById('mobileOverlay');
|
|
@@ -1002,7 +1003,9 @@
|
|
| 1002 |
autoGrow(el) { el.style.height = 'auto'; el.style.height = Math.min(el.scrollHeight, 180) + 'px'; },
|
| 1003 |
scrollToBottom(smooth = false) {
|
| 1004 |
const c = document.getElementById('chatContainer');
|
| 1005 |
-
|
|
|
|
|
|
|
| 1006 |
},
|
| 1007 |
escape(s) { return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); },
|
| 1008 |
showAuthMsg(msg, isError=true) {
|
|
@@ -1028,9 +1031,12 @@
|
|
| 1028 |
const chatContainerEl = document.getElementById('chatContainer');
|
| 1029 |
const scrollBtnEl = document.getElementById('scrollToBottomBtn');
|
| 1030 |
chatContainerEl.addEventListener('scroll', () => {
|
| 1031 |
-
|
|
|
|
|
|
|
| 1032 |
scrollBtnEl.classList.add('visible');
|
| 1033 |
} else {
|
|
|
|
| 1034 |
scrollBtnEl.classList.remove('visible');
|
| 1035 |
}
|
| 1036 |
});
|
|
@@ -1165,6 +1171,7 @@
|
|
| 1165 |
TTSManager.autoPrepare(msgId, msg.content, botObj.listenBtn);
|
| 1166 |
}
|
| 1167 |
}
|
|
|
|
| 1168 |
setTimeout(() => UI.scrollToBottom(true), 200);
|
| 1169 |
if(window.innerWidth <= 900) UI.toggleSidebar();
|
| 1170 |
}
|
|
@@ -1174,6 +1181,7 @@
|
|
| 1174 |
if(State.isProcessing) return;
|
| 1175 |
State.currentThreadId = null; State.currentTitle = null; State.history = [];
|
| 1176 |
document.getElementById('chatMessages').innerHTML = ''; UI.updateWelcomeScreen();
|
|
|
|
| 1177 |
if(window.innerWidth <= 900) UI.toggleSidebar();
|
| 1178 |
},
|
| 1179 |
saveCurrent() {
|
|
@@ -1192,6 +1200,7 @@
|
|
| 1192 |
State.currentTitle = null;
|
| 1193 |
document.getElementById('chatMessages').innerHTML = '';
|
| 1194 |
UI.updateWelcomeScreen();
|
|
|
|
| 1195 |
fetch(Config.GAS_URL, { method: 'POST', body: JSON.stringify({action: "clear_all_chats", email: State.user})}).then(() => this.syncAllChats());
|
| 1196 |
}
|
| 1197 |
},
|
|
@@ -1322,7 +1331,9 @@
|
|
| 1322 |
const c = document.getElementById('chatMessages');
|
| 1323 |
const w = document.createElement('div'); w.className = 'message-wrapper';
|
| 1324 |
w.innerHTML = `<div class="user-message">${attachUI}${txt ? UI.escape(txt) : ''}</div>`;
|
| 1325 |
-
c.appendChild(w);
|
|
|
|
|
|
|
| 1326 |
},
|
| 1327 |
renderBot(msgId) {
|
| 1328 |
const c = document.getElementById('chatMessages');
|
|
@@ -1340,7 +1351,8 @@
|
|
| 1340 |
</div>
|
| 1341 |
</div>
|
| 1342 |
</div>`;
|
| 1343 |
-
c.appendChild(w);
|
|
|
|
| 1344 |
return { contentDiv: document.getElementById(`bot-content-${msgId}`), listenBtn: document.getElementById(`listen-btn-${msgId}`) };
|
| 1345 |
},
|
| 1346 |
parseAndRender(fullText, isSearching, isProcessing, container) {
|
|
|
|
| 640 |
<div id="chatMessages"></div>
|
| 641 |
</div>
|
| 642 |
|
| 643 |
+
<button id="scrollToBottomBtn" class="btn-scroll-bottom" onclick="UI.scrollToBottom(true); UI.autoScroll = true;" title="Go to latest">
|
| 644 |
<svg style="width:20px;height:20px;" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
| 645 |
<line x1="12" y1="5" x2="12" y2="19"></line>
|
| 646 |
<polyline points="19 12 12 19 5 12"></polyline>
|
|
|
|
| 988 |
};
|
| 989 |
|
| 990 |
const UI = {
|
| 991 |
+
autoScroll: true, // intelligent auto-scroll flag
|
| 992 |
toggleSidebar() {
|
| 993 |
const sb = document.getElementById('sidebar');
|
| 994 |
const overlay = document.getElementById('mobileOverlay');
|
|
|
|
| 1003 |
autoGrow(el) { el.style.height = 'auto'; el.style.height = Math.min(el.scrollHeight, 180) + 'px'; },
|
| 1004 |
scrollToBottom(smooth = false) {
|
| 1005 |
const c = document.getElementById('chatContainer');
|
| 1006 |
+
if (this.autoScroll) {
|
| 1007 |
+
c.scrollTo({ top: c.scrollHeight, behavior: smooth ? 'smooth' : 'auto' });
|
| 1008 |
+
}
|
| 1009 |
},
|
| 1010 |
escape(s) { return s.replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>'); },
|
| 1011 |
showAuthMsg(msg, isError=true) {
|
|
|
|
| 1031 |
const chatContainerEl = document.getElementById('chatContainer');
|
| 1032 |
const scrollBtnEl = document.getElementById('scrollToBottomBtn');
|
| 1033 |
chatContainerEl.addEventListener('scroll', () => {
|
| 1034 |
+
const scrollBottom = chatContainerEl.scrollHeight - chatContainerEl.scrollTop - chatContainerEl.clientHeight;
|
| 1035 |
+
if (scrollBottom > 50) {
|
| 1036 |
+
UI.autoScroll = false;
|
| 1037 |
scrollBtnEl.classList.add('visible');
|
| 1038 |
} else {
|
| 1039 |
+
UI.autoScroll = true;
|
| 1040 |
scrollBtnEl.classList.remove('visible');
|
| 1041 |
}
|
| 1042 |
});
|
|
|
|
| 1171 |
TTSManager.autoPrepare(msgId, msg.content, botObj.listenBtn);
|
| 1172 |
}
|
| 1173 |
}
|
| 1174 |
+
UI.autoScroll = true;
|
| 1175 |
setTimeout(() => UI.scrollToBottom(true), 200);
|
| 1176 |
if(window.innerWidth <= 900) UI.toggleSidebar();
|
| 1177 |
}
|
|
|
|
| 1181 |
if(State.isProcessing) return;
|
| 1182 |
State.currentThreadId = null; State.currentTitle = null; State.history = [];
|
| 1183 |
document.getElementById('chatMessages').innerHTML = ''; UI.updateWelcomeScreen();
|
| 1184 |
+
UI.autoScroll = true;
|
| 1185 |
if(window.innerWidth <= 900) UI.toggleSidebar();
|
| 1186 |
},
|
| 1187 |
saveCurrent() {
|
|
|
|
| 1200 |
State.currentTitle = null;
|
| 1201 |
document.getElementById('chatMessages').innerHTML = '';
|
| 1202 |
UI.updateWelcomeScreen();
|
| 1203 |
+
UI.autoScroll = true;
|
| 1204 |
fetch(Config.GAS_URL, { method: 'POST', body: JSON.stringify({action: "clear_all_chats", email: State.user})}).then(() => this.syncAllChats());
|
| 1205 |
}
|
| 1206 |
},
|
|
|
|
| 1331 |
const c = document.getElementById('chatMessages');
|
| 1332 |
const w = document.createElement('div'); w.className = 'message-wrapper';
|
| 1333 |
w.innerHTML = `<div class="user-message">${attachUI}${txt ? UI.escape(txt) : ''}</div>`;
|
| 1334 |
+
c.appendChild(w);
|
| 1335 |
+
UI.autoScroll = true; // when user sends a message, we want to scroll to bottom
|
| 1336 |
+
UI.scrollToBottom();
|
| 1337 |
},
|
| 1338 |
renderBot(msgId) {
|
| 1339 |
const c = document.getElementById('chatMessages');
|
|
|
|
| 1351 |
</div>
|
| 1352 |
</div>
|
| 1353 |
</div>`;
|
| 1354 |
+
c.appendChild(w);
|
| 1355 |
+
UI.scrollToBottom();
|
| 1356 |
return { contentDiv: document.getElementById(`bot-content-${msgId}`), listenBtn: document.getElementById(`listen-btn-${msgId}`) };
|
| 1357 |
},
|
| 1358 |
parseAndRender(fullText, isSearching, isProcessing, container) {
|