diff --git a/src/components/modals/FilePreviewModal.astro b/src/components/modals/FilePreviewModal.astro
index 4ec963e..94af965 100644
--- a/src/components/modals/FilePreviewModal.astro
+++ b/src/components/modals/FilePreviewModal.astro
@@ -45,6 +45,17 @@ const {
{
@@ -141,9 +177,10 @@ const {
break;
case "pdf":
- element = document.createElement("iframe");
+ element = document.createElement("embed");
element.className = "w-full h-full";
- element.src = file.url;
+ element.type = "application/pdf";
+ element.src = file.url + "#toolbar=0&navpanes=0";
break;
default:
@@ -164,16 +201,89 @@ const {
return element;
}
- showFile(file) {
+ showLoading(isMultiple = false) {
+ if (isMultiple) {
+ if (this.multipleLoadingElement) {
+ this.multipleLoadingElement.classList.remove("hidden");
+ }
+ if (this.fileGrid) {
+ this.fileGrid.classList.add("hidden");
+ }
+ } else {
+ if (this.loadingElement) {
+ this.loadingElement.classList.remove("hidden");
+ }
+ if (this.previewContainer) {
+ this.previewContainer.classList.add("hidden");
+ }
+ }
+ }
+
+ hideLoading(isMultiple = false) {
+ if (isMultiple) {
+ if (this.multipleLoadingElement) {
+ this.multipleLoadingElement.classList.add("hidden");
+ }
+ if (this.fileGrid) {
+ this.fileGrid.classList.remove("hidden");
+ }
+ } else {
+ if (this.loadingElement) {
+ this.loadingElement.classList.add("hidden");
+ }
+ if (this.previewContainer) {
+ this.previewContainer.classList.remove("hidden");
+ }
+ }
+ }
+
+ async showFile(file) {
this.titleElement.textContent = file.name;
this.externalLink.href = file.url;
- // Clear previous preview
- this.previewContainer.innerHTML = "";
+ // Show loading state
+ this.showLoading(false);
- // Create and append new preview
- const previewElement = this.createPreviewElement(file);
- this.previewContainer.appendChild(previewElement);
+ try {
+ // Clear previous preview
+ this.previewContainer.innerHTML = "";
+
+ // Create and append new preview
+ const previewElement = this.createPreviewElement(file);
+
+ // Only wait for images to load, PDFs and other files load in their own context
+ if (previewElement instanceof HTMLImageElement) {
+ await new Promise((resolve, reject) => {
+ previewElement.onload = resolve;
+ previewElement.onerror = reject;
+ // Add a timeout to prevent infinite loading
+ setTimeout(reject, 10000); // 10 second timeout
+ }).catch((error) => {
+ console.warn("Image load timeout or error:", error);
+ // Continue anyway, the image might still load
+ });
+ }
+
+ this.previewContainer.appendChild(previewElement);
+ } catch (error) {
+ console.error("Error loading file:", error);
+ this.previewContainer.innerHTML = `
+
+ `;
+ } finally {
+ // Hide loading state after a short delay to ensure UI elements are ready
+ setTimeout(() => {
+ this.hideLoading(false);
+ }, 500);
+ }
// Show single view
this.singleView.classList.remove("hidden");
@@ -216,26 +326,34 @@ const {
return card;
}
- show(files) {
+ async show(files) {
+ this.modal.showModal();
+
if (!Array.isArray(files)) {
// Single file
- this.showFile(files);
+ await this.showFile(files);
} else if (files.length === 1) {
// Single file in array
- this.showFile(files[0]);
+ await this.showFile(files[0]);
} else {
// Multiple files
this.singleView.classList.add("hidden");
this.multipleView.classList.remove("hidden");
- // Clear and populate file grid
- this.fileGrid.innerHTML = "";
- files.forEach((file) => {
- this.fileGrid.appendChild(this.createFileCard(file));
- });
- }
+ // Show loading state
+ this.showLoading(true);
- this.modal.showModal();
+ try {
+ // Clear and populate file grid
+ this.fileGrid.innerHTML = "";
+ files.forEach((file) => {
+ this.fileGrid.appendChild(this.createFileCard(file));
+ });
+ } finally {
+ // Hide loading state
+ this.hideLoading(true);
+ }
+ }
}
close() {