ikraamkb commited on
Commit
b097a6d
·
verified ·
1 Parent(s): 42a453f

Update static/application.js

Browse files
Files changed (1) hide show
  1. static/application.js +35 -3
static/application.js CHANGED
@@ -15,8 +15,8 @@ document.addEventListener("DOMContentLoaded", () => {
15
  fileInput.style.display = "none";
16
  document.body.appendChild(fileInput);
17
 
18
- fileBtn.addEventListener("click", () => fileInput.click());
19
- imageBtn.addEventListener("click", () => fileInput.click());
20
 
21
  fileInput.addEventListener("change", () => {
22
  const file = fileInput.files[0];
@@ -31,7 +31,39 @@ document.addEventListener("DOMContentLoaded", () => {
31
  convo.scrollTop = convo.scrollHeight;
32
  }
33
  });
34
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
36
  const bubble = document.createElement("div");
37
  bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;
 
15
  fileInput.style.display = "none";
16
  document.body.appendChild(fileInput);
17
 
18
+ fileBtn.addEventListener("click", () => fileUpload.click());
19
+ imageBtn.addEventListener("click", () => imageUpload.click());
20
 
21
  fileInput.addEventListener("change", () => {
22
  const file = fileInput.files[0];
 
31
  convo.scrollTop = convo.scrollHeight;
32
  }
33
  });
34
+ fileUpload.addEventListener('change', (e) => {
35
+ if (e.target.files.length > 0) {
36
+ const file = e.target.files[0];
37
+ const validDocTypes = [
38
+ 'application/pdf',
39
+ 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
40
+ 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
41
+ 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
42
+ ];
43
+
44
+ if (validDocTypes.includes(file.type)) {
45
+ console.log('Valid document selected:', file.name);
46
+ // Handle the document file here
47
+ } else {
48
+ alert('Please select a valid document (PDF, DOCX, PPTX, or XLSX)');
49
+ fileUpload.value = ''; // Reset the input
50
+ }
51
+ }
52
+ });
53
+ imageUpload.addEventListener('change', (e) => {
54
+ if (e.target.files.length > 0) {
55
+ const file = e.target.files[0];
56
+ const validImageTypes = ['image/jpeg', 'image/png', 'image/gif', 'image/webp'];
57
+
58
+ if (validImageTypes.includes(file.type)) {
59
+ console.log('Valid image selected:', file.name);
60
+ // Handle the image file here
61
+ } else {
62
+ alert('Please select a valid image (JPEG, PNG, GIF, or WEBP)');
63
+ imageUpload.value = ''; // Reset the input
64
+ }
65
+ }
66
+ });
67
  function createMessageBubble(text, sender = "You", audioSrc = null, fileName = null) {
68
  const bubble = document.createElement("div");
69
  bubble.className = `bubble ${sender === "You" ? "right" : "left"}`;