Spaces:
Running
Running
Update static/application.js
Browse files- static/application.js +27 -42
static/application.js
CHANGED
@@ -167,7 +167,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
167 |
const sendBtn = document.querySelector(".sendingQA");
|
168 |
const fileBtn = document.querySelector(".fa-file");
|
169 |
const imageBtn = document.querySelector(".fa-image");
|
170 |
-
const resetBtn = document.querySelector(".reset-chat");
|
171 |
|
172 |
let selectedFile = null;
|
173 |
let filePreviewBubble = null;
|
@@ -204,7 +203,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
204 |
}
|
205 |
});
|
206 |
|
207 |
-
// Drag & drop
|
208 |
convo.addEventListener("dragover", (e) => {
|
209 |
e.preventDefault();
|
210 |
convo.classList.add("drag-over");
|
@@ -232,14 +230,6 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
232 |
}
|
233 |
});
|
234 |
|
235 |
-
// Reset chat
|
236 |
-
resetBtn.addEventListener("click", () => {
|
237 |
-
convo.innerHTML = "";
|
238 |
-
selectedFile = null;
|
239 |
-
filePreviewBubble = null;
|
240 |
-
input.value = "";
|
241 |
-
});
|
242 |
-
|
243 |
function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
|
244 |
const bubble = document.createElement("div");
|
245 |
bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
|
@@ -271,29 +261,24 @@ document.addEventListener("DOMContentLoaded", () => {
|
|
271 |
icon.style.cursor = "pointer";
|
272 |
icon.style.fontSize = "18px";
|
273 |
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
let isMuted = false;
|
278 |
-
let audio = new Audio(audioSrc);
|
279 |
-
audio.play();
|
280 |
-
|
281 |
-
icon.addEventListener("click", () => {
|
282 |
-
if (isMuted) {
|
283 |
-
// Recreate audio to force replay
|
284 |
-
audio = new Audio(audioSrc);
|
285 |
-
audio.play();
|
286 |
-
isMuted = false;
|
287 |
-
icon.classList.replace("fa-volume-xmark", "fa-volume-high");
|
288 |
-
icon.title = "Click to mute";
|
289 |
-
} else {
|
290 |
-
audio.pause();
|
291 |
-
isMuted = true;
|
292 |
-
icon.classList.replace("fa-volume-high", "fa-volume-xmark");
|
293 |
-
icon.title = "Click to unmute";
|
294 |
-
}
|
295 |
-
});
|
296 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
297 |
|
298 |
message.appendChild(icon);
|
299 |
}
|
@@ -307,7 +292,6 @@ icon.addEventListener("click", () => {
|
|
307 |
}
|
308 |
|
309 |
sendBtn.addEventListener("click", async () => {
|
310 |
-
input.value = "";
|
311 |
const question = input.value.trim();
|
312 |
if (!question) return;
|
313 |
|
@@ -324,7 +308,6 @@ icon.addEventListener("click", () => {
|
|
324 |
createMessageBubble(question, "You", null, selectedFile.name);
|
325 |
const thinkingBubble = createMessageBubble("🧠 Let me think...", "Chris");
|
326 |
|
327 |
-
// Rewrap file if needed (for reuse in FormData)
|
328 |
const wrappedFile = new File([selectedFile], selectedFile.name, {
|
329 |
type: selectedFile.type,
|
330 |
});
|
@@ -354,18 +337,20 @@ icon.addEventListener("click", () => {
|
|
354 |
icon.style.fontSize = "18px";
|
355 |
icon.style.marginLeft = "10px";
|
356 |
|
357 |
-
|
358 |
-
|
359 |
|
|
|
360 |
icon.addEventListener("click", () => {
|
361 |
-
if (
|
362 |
-
|
363 |
-
|
364 |
-
|
365 |
icon.classList.replace("fa-volume-xmark", "fa-volume-high");
|
366 |
icon.title = "Click to mute";
|
367 |
} else {
|
368 |
-
|
|
|
369 |
icon.classList.replace("fa-volume-high", "fa-volume-xmark");
|
370 |
icon.title = "Click to unmute";
|
371 |
}
|
@@ -381,6 +366,6 @@ icon.addEventListener("click", () => {
|
|
381 |
message.innerText = "⚠️ Chris had trouble responding.";
|
382 |
}
|
383 |
|
384 |
-
|
385 |
});
|
386 |
});
|
|
|
167 |
const sendBtn = document.querySelector(".sendingQA");
|
168 |
const fileBtn = document.querySelector(".fa-file");
|
169 |
const imageBtn = document.querySelector(".fa-image");
|
|
|
170 |
|
171 |
let selectedFile = null;
|
172 |
let filePreviewBubble = null;
|
|
|
203 |
}
|
204 |
});
|
205 |
|
|
|
206 |
convo.addEventListener("dragover", (e) => {
|
207 |
e.preventDefault();
|
208 |
convo.classList.add("drag-over");
|
|
|
230 |
}
|
231 |
});
|
232 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
233 |
function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
|
234 |
const bubble = document.createElement("div");
|
235 |
bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
|
|
|
261 |
icon.style.cursor = "pointer";
|
262 |
icon.style.fontSize = "18px";
|
263 |
|
264 |
+
let currentAudio = new Audio(audioSrc);
|
265 |
+
currentAudio.play();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
266 |
|
267 |
+
let isMuted = false;
|
268 |
+
icon.addEventListener("click", () => {
|
269 |
+
if (isMuted) {
|
270 |
+
currentAudio = new Audio(audioSrc); // reset audio
|
271 |
+
currentAudio.play();
|
272 |
+
isMuted = false;
|
273 |
+
icon.classList.replace("fa-volume-xmark", "fa-volume-high");
|
274 |
+
icon.title = "Click to mute";
|
275 |
+
} else {
|
276 |
+
currentAudio.pause();
|
277 |
+
isMuted = true;
|
278 |
+
icon.classList.replace("fa-volume-high", "fa-volume-xmark");
|
279 |
+
icon.title = "Click to unmute";
|
280 |
+
}
|
281 |
+
});
|
282 |
|
283 |
message.appendChild(icon);
|
284 |
}
|
|
|
292 |
}
|
293 |
|
294 |
sendBtn.addEventListener("click", async () => {
|
|
|
295 |
const question = input.value.trim();
|
296 |
if (!question) return;
|
297 |
|
|
|
308 |
createMessageBubble(question, "You", null, selectedFile.name);
|
309 |
const thinkingBubble = createMessageBubble("🧠 Let me think...", "Chris");
|
310 |
|
|
|
311 |
const wrappedFile = new File([selectedFile], selectedFile.name, {
|
312 |
type: selectedFile.type,
|
313 |
});
|
|
|
337 |
icon.style.fontSize = "18px";
|
338 |
icon.style.marginLeft = "10px";
|
339 |
|
340 |
+
let currentAudio = new Audio(audioSrc);
|
341 |
+
currentAudio.play();
|
342 |
|
343 |
+
let isMuted = false;
|
344 |
icon.addEventListener("click", () => {
|
345 |
+
if (isMuted) {
|
346 |
+
currentAudio = new Audio(audioSrc); // restart audio
|
347 |
+
currentAudio.play();
|
348 |
+
isMuted = false;
|
349 |
icon.classList.replace("fa-volume-xmark", "fa-volume-high");
|
350 |
icon.title = "Click to mute";
|
351 |
} else {
|
352 |
+
currentAudio.pause();
|
353 |
+
isMuted = true;
|
354 |
icon.classList.replace("fa-volume-high", "fa-volume-xmark");
|
355 |
icon.title = "Click to unmute";
|
356 |
}
|
|
|
366 |
message.innerText = "⚠️ Chris had trouble responding.";
|
367 |
}
|
368 |
|
369 |
+
input.value = "";
|
370 |
});
|
371 |
});
|