Spaces:
Sleeping
Sleeping
Update static/appS.js
Browse files- static/appS.js +71 -64
static/appS.js
CHANGED
|
@@ -583,78 +583,85 @@ document.addEventListener('DOMContentLoaded', () => {
|
|
| 583 |
}
|
| 584 |
}
|
| 585 |
|
| 586 |
-
|
| 587 |
-
|
| 588 |
-
|
| 589 |
-
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
|
| 593 |
-
|
| 594 |
-
|
| 595 |
-
|
| 596 |
-
|
| 597 |
-
|
| 598 |
-
|
| 599 |
-
|
| 600 |
-
|
| 601 |
-
|
| 602 |
-
|
| 603 |
-
|
| 604 |
-
|
| 605 |
-
|
| 606 |
-
|
| 607 |
-
|
| 608 |
-
|
| 609 |
-
|
| 610 |
-
|
| 611 |
-
|
| 612 |
-
|
| 613 |
-
|
| 614 |
-
|
| 615 |
-
|
| 616 |
-
|
| 617 |
-
|
| 618 |
-
|
| 619 |
-
|
| 620 |
-
|
| 621 |
-
|
| 622 |
-
|
| 623 |
-
|
| 624 |
-
|
| 625 |
-
|
| 626 |
-
|
| 627 |
-
|
| 628 |
-
}
|
| 629 |
-
|
| 630 |
-
|
| 631 |
-
|
| 632 |
-
|
| 633 |
-
|
| 634 |
-
|
| 635 |
-
downloadLink.target = "_blank";
|
| 636 |
-
downloadLink.download = fileName.split('/').pop();
|
| 637 |
|
| 638 |
-
|
| 639 |
-
|
| 640 |
-
downloadIcon.style.fontSize = "18px";
|
| 641 |
-
downloadIcon.style.cursor = "pointer";
|
| 642 |
|
| 643 |
-
|
| 644 |
-
|
| 645 |
-
|
|
|
|
|
|
|
|
|
|
| 646 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 647 |
|
| 648 |
-
|
|
|
|
| 649 |
}
|
| 650 |
|
| 651 |
-
|
| 652 |
-
bubble.appendChild(message);
|
| 653 |
-
convo.appendChild(bubble);
|
| 654 |
-
convo.scrollTop = convo.scrollHeight;
|
| 655 |
-
return bubble;
|
| 656 |
}
|
| 657 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 658 |
async function handleSubmit() {
|
| 659 |
if (!selectedFile) {
|
| 660 |
alert("Please upload a file first");
|
|
|
|
| 583 |
}
|
| 584 |
}
|
| 585 |
|
| 586 |
+
function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
|
| 587 |
+
const bubble = document.createElement('div');
|
| 588 |
+
bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
|
| 589 |
+
bubble.style.maxWidth = "50%";
|
| 590 |
+
bubble.style.wordWrap = "break-word";
|
| 591 |
+
|
| 592 |
+
const label = document.createElement('div');
|
| 593 |
+
label.className = "label";
|
| 594 |
+
label.textContent = sender;
|
| 595 |
+
|
| 596 |
+
const message = document.createElement('div');
|
| 597 |
+
message.className = "text";
|
| 598 |
+
message.style.whiteSpace = "pre-wrap";
|
| 599 |
+
message.style.display = "flex";
|
| 600 |
+
message.style.flexDirection = "column";
|
| 601 |
+
|
| 602 |
+
const textSpan = document.createElement("span");
|
| 603 |
+
textSpan.innerHTML = text;
|
| 604 |
+
message.appendChild(textSpan);
|
| 605 |
+
|
| 606 |
+
// ✅ Only define and append icon container if needed
|
| 607 |
+
if (sender !== "You" && (audioSrc || fileName)) {
|
| 608 |
+
const iconContainer = document.createElement('div');
|
| 609 |
+
iconContainer.style.marginTop = "10px";
|
| 610 |
+
iconContainer.style.display = "flex";
|
| 611 |
+
iconContainer.style.justifyContent = "flex-end";
|
| 612 |
+
iconContainer.style.gap = "15px";
|
| 613 |
+
|
| 614 |
+
if (audioSrc) {
|
| 615 |
+
const audio = new Audio(audioSrc);
|
| 616 |
+
const audioIcon = document.createElement("i");
|
| 617 |
+
audioIcon.className = "fa-solid fa-volume-high audio-toggle";
|
| 618 |
+
audioIcon.title = "Play Audio";
|
| 619 |
+
audioIcon.style.cursor = "pointer";
|
| 620 |
+
audioIcon.style.fontSize = "18px";
|
| 621 |
+
|
| 622 |
+
audioIcon.addEventListener("click", () => {
|
| 623 |
+
if (audio.paused) {
|
| 624 |
+
audio.play();
|
| 625 |
+
audioIcon.classList.remove("fa-volume-xmark");
|
| 626 |
+
audioIcon.classList.add("fa-volume-high");
|
| 627 |
+
audioIcon.title = "Mute Audio";
|
| 628 |
+
} else {
|
| 629 |
+
audio.pause();
|
| 630 |
+
audioIcon.classList.remove("fa-volume-high");
|
| 631 |
+
audioIcon.classList.add("fa-volume-xmark");
|
| 632 |
+
audioIcon.title = "Unmute Audio";
|
| 633 |
+
}
|
| 634 |
+
});
|
|
|
|
|
|
|
| 635 |
|
| 636 |
+
iconContainer.appendChild(audioIcon);
|
| 637 |
+
}
|
|
|
|
|
|
|
| 638 |
|
| 639 |
+
if (fileName) {
|
| 640 |
+
const filenameOnly = fileName.split("/").pop();
|
| 641 |
+
const downloadLink = document.createElement('a');
|
| 642 |
+
downloadLink.href = `/files/${filenameOnly}`;
|
| 643 |
+
downloadLink.target = "_blank";
|
| 644 |
+
downloadLink.download = filenameOnly;
|
| 645 |
|
| 646 |
+
const downloadIcon = document.createElement("i");
|
| 647 |
+
downloadIcon.className = "fa-solid fa-file-arrow-down";
|
| 648 |
+
downloadIcon.style.fontSize = "18px";
|
| 649 |
+
downloadIcon.style.cursor = "pointer";
|
| 650 |
|
| 651 |
+
downloadLink.appendChild(downloadIcon);
|
| 652 |
+
iconContainer.appendChild(downloadLink);
|
| 653 |
}
|
| 654 |
|
| 655 |
+
message.appendChild(iconContainer);
|
|
|
|
|
|
|
|
|
|
|
|
|
| 656 |
}
|
| 657 |
|
| 658 |
+
bubble.appendChild(label);
|
| 659 |
+
bubble.appendChild(message);
|
| 660 |
+
convo.appendChild(bubble);
|
| 661 |
+
convo.scrollTop = convo.scrollHeight;
|
| 662 |
+
return bubble;
|
| 663 |
+
}
|
| 664 |
+
|
| 665 |
async function handleSubmit() {
|
| 666 |
if (!selectedFile) {
|
| 667 |
alert("Please upload a file first");
|