fix console errors
This commit is contained in:
parent
d43495ec9d
commit
0ba3142792
1 changed files with 81 additions and 36 deletions
|
@ -664,6 +664,7 @@ const currentPage = eventResponse.page;
|
||||||
<button
|
<button
|
||||||
class="btn btn-ghost btn-sm"
|
class="btn btn-ghost btn-sm"
|
||||||
onclick="window.closeFilePreviewOfficer()"
|
onclick="window.closeFilePreviewOfficer()"
|
||||||
|
type="button"
|
||||||
>
|
>
|
||||||
Close
|
Close
|
||||||
</button>
|
</button>
|
||||||
|
@ -681,7 +682,7 @@ const currentPage = eventResponse.page;
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<form method="dialog" class="modal-backdrop">
|
<form method="dialog" class="modal-backdrop">
|
||||||
<button onclick="window.closeFilePreviewOfficer()">close</button>
|
<button type="button">close</button>
|
||||||
</form>
|
</form>
|
||||||
</dialog>
|
</dialog>
|
||||||
|
|
||||||
|
@ -2370,55 +2371,61 @@ const currentPage = eventResponse.page;
|
||||||
|
|
||||||
// Universal file preview function for officer section
|
// Universal file preview function for officer section
|
||||||
window.previewFileOfficer = function (url: string, filename: string) {
|
window.previewFileOfficer = function (url: string, filename: string) {
|
||||||
console.log("previewFileOfficer called with:", { url, filename });
|
|
||||||
const modal = document.getElementById(
|
const modal = document.getElementById(
|
||||||
"filePreviewModal"
|
"filePreviewModal"
|
||||||
) as HTMLDialogElement;
|
) as HTMLDialogElement;
|
||||||
|
|
||||||
if (modal) {
|
if (!modal) {
|
||||||
console.log("Found all required elements");
|
console.error("Modal element not found");
|
||||||
// Show the modal
|
return;
|
||||||
modal.showModal();
|
|
||||||
|
|
||||||
// Dispatch state change event
|
|
||||||
console.log("Dispatching state change event");
|
|
||||||
window.dispatchEvent(
|
|
||||||
new CustomEvent(FILE_PREVIEW_STATE_CHANGE, {
|
|
||||||
detail: { url, filename },
|
|
||||||
})
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
console.error("Missing required elements:", {
|
|
||||||
modal: !!modal,
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Dispatch state change event before showing modal
|
||||||
|
window.dispatchEvent(
|
||||||
|
new CustomEvent(FILE_PREVIEW_STATE_CHANGE, {
|
||||||
|
detail: { url, filename },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// Show modal after event dispatch
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
modal.showModal();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Close file preview for officer section
|
// Close file preview for officer section
|
||||||
window.closeFilePreviewOfficer = function () {
|
window.closeFilePreviewOfficer = function () {
|
||||||
console.log("closeFilePreviewOfficer called");
|
|
||||||
const modal = document.getElementById(
|
const modal = document.getElementById(
|
||||||
"filePreviewModal"
|
"filePreviewModal"
|
||||||
) as HTMLDialogElement;
|
) as HTMLDialogElement;
|
||||||
const previewContent = document.getElementById("previewContent");
|
const previewContent = document.getElementById("previewContent");
|
||||||
|
|
||||||
if (modal && previewContent) {
|
if (!modal || !previewContent) {
|
||||||
console.log("Resetting preview and closing modal");
|
console.error("Required elements not found");
|
||||||
// Reset the preview
|
return;
|
||||||
const filePreview = previewContent.querySelector(
|
|
||||||
"astro-island"
|
|
||||||
) as any;
|
|
||||||
if (filePreview) {
|
|
||||||
const component = filePreview.querySelector(
|
|
||||||
"[data-astro-cid]"
|
|
||||||
) as any;
|
|
||||||
if (component) {
|
|
||||||
component.setAttribute("url", "");
|
|
||||||
component.setAttribute("filename", "");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
modal.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Reset the preview content
|
||||||
|
const filePreview = previewContent.querySelector("astro-island");
|
||||||
|
if (filePreview) {
|
||||||
|
const component = filePreview.querySelector("[data-astro-cid]");
|
||||||
|
if (component) {
|
||||||
|
component.setAttribute("url", "");
|
||||||
|
component.setAttribute("filename", "");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dispatch cleanup event
|
||||||
|
window.dispatchEvent(
|
||||||
|
new CustomEvent(FILE_PREVIEW_STATE_CHANGE, {
|
||||||
|
detail: { url: "", filename: "" },
|
||||||
|
})
|
||||||
|
);
|
||||||
|
|
||||||
|
// Close modal after cleanup
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
modal.close();
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Update the showFilePreview function for officer section
|
// Update the showFilePreview function for officer section
|
||||||
|
@ -2426,7 +2433,10 @@ const currentPage = eventResponse.page;
|
||||||
url: string;
|
url: string;
|
||||||
name: string;
|
name: string;
|
||||||
}) {
|
}) {
|
||||||
console.log("showFilePreviewOfficer called with:", file);
|
if (!file || !file.url || !file.name) {
|
||||||
|
console.error("Invalid file data provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
window.previewFileOfficer(file.url, file.name);
|
window.previewFileOfficer(file.url, file.name);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -2463,4 +2473,39 @@ const currentPage = eventResponse.page;
|
||||||
// Show modal
|
// Show modal
|
||||||
modal.showModal();
|
modal.showModal();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Add event listeners when the document loads
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
const modal = document.getElementById(
|
||||||
|
"filePreviewModal"
|
||||||
|
) as HTMLDialogElement;
|
||||||
|
if (modal) {
|
||||||
|
// Handle modal close via backdrop
|
||||||
|
modal.addEventListener("click", (e) => {
|
||||||
|
const modalDimensions = modal.getBoundingClientRect();
|
||||||
|
if (
|
||||||
|
e.clientX < modalDimensions.left ||
|
||||||
|
e.clientX > modalDimensions.right ||
|
||||||
|
e.clientY < modalDimensions.top ||
|
||||||
|
e.clientY > modalDimensions.bottom
|
||||||
|
) {
|
||||||
|
window.closeFilePreviewOfficer();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Prevent modal content clicks from closing
|
||||||
|
const modalContent = modal.querySelector(".modal-box");
|
||||||
|
if (modalContent) {
|
||||||
|
modalContent.addEventListener("click", (e) => {
|
||||||
|
e.stopPropagation();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle escape key
|
||||||
|
modal.addEventListener("cancel", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
window.closeFilePreviewOfficer();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue