ikraamkb commited on
Commit
0e2f501
Β·
verified Β·
1 Parent(s): 626fdf6

Update static/appS.js

Browse files
Files changed (1) hide show
  1. static/appS.js +25 -28
static/appS.js CHANGED
@@ -7,11 +7,10 @@ document.addEventListener('DOMContentLoaded', () => {
7
  const sendButtons = document.querySelectorAll('.sendingQA');
8
  const SummarizeInput = document.querySelector(".SummarizeInput");
9
  const CaptionInput = document.querySelector(".CaptionInput");
10
- var gotItButton = document.querySelector('.explainChoix button');
11
- var explainChoixDiv = document.querySelector('.explainChoix');
12
 
13
  let selectedFile = null;
14
- let filePreviewBubble = null;
15
 
16
  // βœ… Default mode: Summarize selected
17
  const summarizeRadio = document.getElementById('summarize-radio');
@@ -66,23 +65,21 @@ document.addEventListener('DOMContentLoaded', () => {
66
  });
67
 
68
  function displayFilePreview(file) {
69
- if (filePreviewBubble) filePreviewBubble.remove();
 
 
 
 
 
70
 
71
- // If it's an image
72
  if (file.type.startsWith('image/')) {
73
  const reader = new FileReader();
74
  reader.onload = (e) => {
75
- filePreviewBubble = document.createElement("div");
76
- filePreviewBubble.className = "file-preview-bubble bubble right";
77
- filePreviewBubble.style.display = "flex";
78
- filePreviewBubble.style.flexDirection = "column";
79
- filePreviewBubble.style.maxWidth = "50%";
80
-
81
  const img = document.createElement("img");
82
  img.src = e.target.result;
83
  img.style.width = "100%";
84
- img.style.height = "200px"; // You can adjust the height if you want
85
- img.style.objectFit = "cover"; // Makes it fill nicely
86
  img.style.borderRadius = "10px";
87
  img.style.marginBottom = "8px";
88
 
@@ -90,18 +87,20 @@ document.addEventListener('DOMContentLoaded', () => {
90
  text.textContent = `πŸ“Ž Selected image: ${file.name}`;
91
  text.style.fontSize = "13px";
92
 
93
- filePreviewBubble.appendChild(img);
94
- filePreviewBubble.appendChild(text);
95
- convo.appendChild(filePreviewBubble);
96
  convo.scrollTop = convo.scrollHeight;
97
  };
98
  reader.readAsDataURL(file);
99
  } else {
100
- // Document preview stays as text
101
- filePreviewBubble = createMessageBubble(
102
- `πŸ“Ž Selected document: ${file.name}`,
103
- "You"
104
- );
 
 
105
  }
106
  }
107
 
@@ -161,13 +160,11 @@ document.addEventListener('DOMContentLoaded', () => {
161
  const downloadLink = document.createElement('a');
162
  downloadLink.href = fileName;
163
  downloadLink.target = "_blank";
164
- downloadLink.download = "summary.pdf"; // βœ… Suggest filename to browser
165
-
166
  const downloadIcon = document.createElement("i");
167
  downloadIcon.className = "fa-solid fa-file-arrow-down";
168
  downloadIcon.style.fontSize = "18px";
169
  downloadIcon.style.cursor = "pointer";
170
-
171
  downloadLink.appendChild(downloadIcon);
172
  iconContainer.appendChild(downloadLink);
173
  }
@@ -210,9 +207,7 @@ document.addEventListener('DOMContentLoaded', () => {
210
  try {
211
  const error = await response.json();
212
  errorMessage = error.detail || error.error || errorMessage;
213
- } catch (e) {
214
- // response not JSON
215
- }
216
  throw new Error(errorMessage);
217
  }
218
 
@@ -237,6 +232,8 @@ document.addEventListener('DOMContentLoaded', () => {
237
  } catch (error) {
238
  thinkingBubble.remove();
239
  createMessageBubble(`⚠️ Error: ${error.message}`, "Aidan");
 
 
240
  }
241
  }
242
 
@@ -262,4 +259,4 @@ document.addEventListener('DOMContentLoaded', () => {
262
  }
263
  `;
264
  document.head.appendChild(style);
265
- });
 
7
  const sendButtons = document.querySelectorAll('.sendingQA');
8
  const SummarizeInput = document.querySelector(".SummarizeInput");
9
  const CaptionInput = document.querySelector(".CaptionInput");
10
+ const gotItButton = document.querySelector('.explainChoix button');
11
+ const explainChoixDiv = document.querySelector('.explainChoix');
12
 
13
  let selectedFile = null;
 
14
 
15
  // βœ… Default mode: Summarize selected
16
  const summarizeRadio = document.getElementById('summarize-radio');
 
65
  });
66
 
67
  function displayFilePreview(file) {
68
+ // βœ… DO NOT remove old previews anymore
69
+ const previewBubble = document.createElement("div");
70
+ previewBubble.className = "file-preview-bubble bubble right";
71
+ previewBubble.style.display = "flex";
72
+ previewBubble.style.flexDirection = "column";
73
+ previewBubble.style.maxWidth = "50%";
74
 
 
75
  if (file.type.startsWith('image/')) {
76
  const reader = new FileReader();
77
  reader.onload = (e) => {
 
 
 
 
 
 
78
  const img = document.createElement("img");
79
  img.src = e.target.result;
80
  img.style.width = "100%";
81
+ img.style.height = "200px";
82
+ img.style.objectFit = "cover";
83
  img.style.borderRadius = "10px";
84
  img.style.marginBottom = "8px";
85
 
 
87
  text.textContent = `πŸ“Ž Selected image: ${file.name}`;
88
  text.style.fontSize = "13px";
89
 
90
+ previewBubble.appendChild(img);
91
+ previewBubble.appendChild(text);
92
+ convo.appendChild(previewBubble);
93
  convo.scrollTop = convo.scrollHeight;
94
  };
95
  reader.readAsDataURL(file);
96
  } else {
97
+ const text = document.createElement("span");
98
+ text.textContent = `πŸ“Ž Selected document: ${file.name}`;
99
+ text.style.fontSize = "13px";
100
+
101
+ previewBubble.appendChild(text);
102
+ convo.appendChild(previewBubble);
103
+ convo.scrollTop = convo.scrollHeight;
104
  }
105
  }
106
 
 
160
  const downloadLink = document.createElement('a');
161
  downloadLink.href = fileName;
162
  downloadLink.target = "_blank";
163
+ downloadLink.download = "summary.pdf"; // βœ… Suggest filename
 
164
  const downloadIcon = document.createElement("i");
165
  downloadIcon.className = "fa-solid fa-file-arrow-down";
166
  downloadIcon.style.fontSize = "18px";
167
  downloadIcon.style.cursor = "pointer";
 
168
  downloadLink.appendChild(downloadIcon);
169
  iconContainer.appendChild(downloadLink);
170
  }
 
207
  try {
208
  const error = await response.json();
209
  errorMessage = error.detail || error.error || errorMessage;
210
+ } catch (e) {}
 
 
211
  throw new Error(errorMessage);
212
  }
213
 
 
232
  } catch (error) {
233
  thinkingBubble.remove();
234
  createMessageBubble(`⚠️ Error: ${error.message}`, "Aidan");
235
+ } finally {
236
+ selectedFile = null; // βœ… Reset selected file AFTER send
237
  }
238
  }
239
 
 
259
  }
260
  `;
261
  document.head.appendChild(style);
262
+ });