ikraamkb commited on
Commit
a418dd2
·
verified ·
1 Parent(s): 05bcdca

Update static/appS.js

Browse files
Files changed (1) hide show
  1. static/appS.js +71 -64
static/appS.js CHANGED
@@ -583,78 +583,85 @@ document.addEventListener('DOMContentLoaded', () => {
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
-
591
- const label = document.createElement('div');
592
- label.className = "label";
593
- label.textContent = sender;
594
-
595
- const message = document.createElement('div');
596
- message.className = "text";
597
- message.style.whiteSpace = "pre-wrap";
598
- message.style.display = "flex";
599
- message.style.flexDirection = "column";
600
-
601
- const span = document.createElement("span");
602
- span.innerHTML = text;
603
- message.appendChild(span);
604
-
605
- if (sender !== "You" && (audioSrc || fileName)) {
606
- const iconRow = document.createElement('div');
607
- iconRow.style.marginTop = "10px";
608
- iconRow.style.display = "flex";
609
- iconRow.style.justifyContent = "flex-end";
610
- iconRow.style.gap = "15px";
611
-
612
- if (audioSrc) {
613
- const audio = new Audio(audioSrc);
614
- const icon = document.createElement("i");
615
- icon.className = "fa-solid fa-volume-high audio-toggle";
616
- icon.style.cursor = "pointer";
617
- icon.title = "Play Audio";
618
- icon.addEventListener("click", () => {
619
- if (audio.paused) {
620
- audio.play();
621
- icon.classList.replace("fa-volume-xmark", "fa-volume-high");
622
- icon.title = "Mute Audio";
623
- } else {
624
- audio.pause();
625
- icon.classList.replace("fa-volume-high", "fa-volume-xmark");
626
- icon.title = "Unmute Audio";
627
- }
628
- });
629
- iconRow.appendChild(icon);
630
- }
631
-
632
- if (fileName) {
633
- const downloadLink = document.createElement('a');
634
- downloadLink.href = `/files/${fileName.split('/').pop()}`;
635
- downloadLink.target = "_blank";
636
- downloadLink.download = fileName.split('/').pop();
637
 
638
- const downloadIcon = document.createElement("i");
639
- downloadIcon.className = "fa-solid fa-file-arrow-down";
640
- downloadIcon.style.fontSize = "18px";
641
- downloadIcon.style.cursor = "pointer";
642
 
643
- downloadLink.appendChild(downloadIcon);
644
- iconContainer.appendChild(downloadLink);
645
- }
 
 
 
646
 
 
 
 
 
647
 
648
- message.appendChild(iconRow);
 
649
  }
650
 
651
- bubble.appendChild(label);
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");