diff --git a/src/components/modals/FilePreviewModal.astro b/src/components/modals/FilePreviewModal.astro index 0e639d0..69475d6 100644 --- a/src/components/modals/FilePreviewModal.astro +++ b/src/components/modals/FilePreviewModal.astro @@ -399,24 +399,24 @@ const { } createFileCard(file) { - const fileType = this.getFileType(file.name); const card = document.createElement("div"); card.className = "card bg-base-200 hover:bg-base-300 cursor-pointer transition-colors"; + const fileType = this.getFileType(file.name); let preview = ""; + if (fileType === "image") { preview = `
${this.getFileTypeLabel(fileType)}
`; - card.addEventListener("click", () => this.showFile(file)); return card; } + getFileTypeLabel(fileType) { + switch (fileType) { + case "image": + return "Image"; + case "video": + return "Video"; + case "audio": + return "Audio"; + case "pdf": + return "PDF Document"; + case "word": + return "Word Document"; + case "excel": + return "Excel Spreadsheet"; + case "powerpoint": + return "PowerPoint Presentation"; + case "text": + return "Text Document"; + case "code": + return "Code File"; + case "archive": + return "Archive"; + default: + return "File"; + } + } + async show(files) { this.modal.showModal(); - if (!Array.isArray(files)) { - // Single file - await this.showFile(files); - } else if (files.length === 1) { - // Single file in array - await this.showFile(files[0]); - } else { - // Multiple files - this.singleView.classList.add("hidden"); - this.multipleView.classList.remove("hidden"); + // Show loading state immediately + this.showLoading(false); + this.showLoading(true); - // Show loading state - this.showLoading(true); + try { + // Normalize input to array + const fileArray = Array.isArray(files) ? files : [files]; + + // Handle empty files + if (fileArray.length === 0) { + this.previewContainer.innerHTML = ` +No files available
+Failed to load files
+${error instanceof Error ? error.message : "Unknown error"}
+