@@ -127,6 +127,7 @@ <h3 class="text-lg font-bold text-[#E5E7EB] mb-4 flex items-center">
127127 imageFiles: [],
128128 audioFiles: [],
129129 textFiles: [],
130+ attachedFiles: [],
130131 currentPlaceholder: 'Send a message...',
131132 placeholderIndex: 0,
132133 charIndex: 0,
@@ -241,6 +242,30 @@ <h3 class="text-lg font-bold text-[#E5E7EB] mb-4 flex items-center">
241242 } else {
242243 this.resumeTyping();
243244 }
245+ },
246+ handleFileSelection(files, fileType) {
247+ Array.from(files).forEach(file => {
248+ // Check if file already exists
249+ const exists = this.attachedFiles.some(f => f.name === file.name && f.type === fileType);
250+ if (!exists) {
251+ this.attachedFiles.push({ name: file.name, type: fileType });
252+ }
253+ });
254+ },
255+ removeAttachedFile(fileType, fileName) {
256+ // Remove from attachedFiles array
257+ const index = this.attachedFiles.findIndex(f => f.name === fileName && f.type === fileType);
258+ if (index !== -1) {
259+ this.attachedFiles.splice(index, 1);
260+ }
261+ // Remove from corresponding file array
262+ if (fileType === 'image') {
263+ this.imageFiles = this.imageFiles.filter(f => f.name !== fileName);
264+ } else if (fileType === 'audio') {
265+ this.audioFiles = this.audioFiles.filter(f => f.name !== fileName);
266+ } else if (fileType === 'file') {
267+ this.textFiles = this.textFiles.filter(f => f.name !== fileName);
268+ }
244269 }
245270 } ">
246271 <!-- Model Selector -->
@@ -265,6 +290,24 @@ <h3 class="text-lg font-bold text-[#E5E7EB] mb-4 flex items-center">
265290
266291 <!-- Input Bar -->
267292 < form @submit.prevent ="startChat($event) " class ="relative w-full ">
293+ <!-- Attachment Tags - Show above input when files are attached -->
294+ < div x-show ="attachedFiles.length > 0 " class ="mb-3 flex flex-wrap gap-2 items-center ">
295+ < template x-for ="(file, index) in attachedFiles " :key ="index ">
296+ < div class ="inline-flex items-center gap-2 px-3 py-1.5 rounded-lg text-sm bg-[#38BDF8]/20 border border-[#38BDF8]/40 text-[#E5E7EB] ">
297+ < i :class ="file.type === 'image' ? 'fa-solid fa-image' : file.type === 'audio' ? 'fa-solid fa-microphone' : 'fa-solid fa-file' " class ="text-[#38BDF8] "> </ i >
298+ < span x-text ="file.name " class ="max-w-[200px] truncate "> </ span >
299+ < button
300+ type ="button "
301+ @click ="attachedFiles.splice(index, 1); removeAttachedFile(file.type, file.name) "
302+ class ="ml-1 text-[#94A3B8] hover:text-[#E5E7EB] transition-colors "
303+ title ="Remove attachment "
304+ >
305+ < i class ="fa-solid fa-times text-xs "> </ i >
306+ </ button >
307+ </ div >
308+ </ template >
309+ </ div >
310+
268311 < div class ="relative w-full bg-[#1E293B] border border-[#38BDF8]/20 rounded-xl focus-within:ring-2 focus-within:ring-[#38BDF8]/50 focus-within:border-[#38BDF8] transition-all duration-200 ">
269312 < textarea
270313 x-model ="inputValue "
@@ -279,7 +322,6 @@ <h3 class="text-lg font-bold text-[#E5E7EB] mb-4 flex items-center">
279322 @input ="handleInput() "
280323 rows ="2 "
281324 > </ textarea >
282- < span x-show ="fileName " x-text ="fileName " class ="absolute right-16 top-3 text-[#94A3B8] text-xs mr-2 "> </ span >
283325
284326 <!-- Attachment Buttons -->
285327 < button
@@ -321,23 +363,23 @@ <h3 class="text-lg font-bold text-[#E5E7EB] mb-4 flex items-center">
321363 multiple
322364 accept ="image/* "
323365 style ="display: none; "
324- @change ="imageFiles = Array.from($event.target.files); fileName = imageFiles.length > 0 ? imageFiles.length + ' image(s) selected' : '' "
366+ @change ="imageFiles = Array.from($event.target.files); handleFileSelection($event.target.files, ' image') "
325367 />
326368 < input
327369 id ="index_input_audio "
328370 type ="file "
329371 multiple
330372 accept ="audio/* "
331373 style ="display: none; "
332- @change ="audioFiles = Array.from($event.target.files); fileName = audioFiles.length > 0 ? audioFiles.length + ' audio file(s) selected' : '' "
374+ @change ="audioFiles = Array.from($event.target.files); handleFileSelection($event.target.files, ' audio') "
333375 />
334376 < input
335377 id ="index_input_file "
336378 type ="file "
337379 multiple
338380 accept =".txt,.md,.pdf "
339381 style ="display: none; "
340- @change ="textFiles = Array.from($event.target.files); fileName = textFiles.length > 0 ? textFiles.length + ' file(s) selected' : '' "
382+ @change ="textFiles = Array.from($event.target.files); handleFileSelection($event.target.files, ' file') "
341383 />
342384 </ div >
343385
0 commit comments