From 98ee9f37102a47e6efec8beef4695256b8aca6db Mon Sep 17 00:00:00 2001 From: chark1es Date: Sat, 1 Feb 2025 00:19:34 -0800 Subject: [PATCH] fix file viewer buttons --- src/components/auth/EventAuth.ts | 189 +++++++----------- .../profile/DefaultProfileView.astro | 23 ++- 2 files changed, 86 insertions(+), 126 deletions(-) diff --git a/src/components/auth/EventAuth.ts b/src/components/auth/EventAuth.ts index f7bc1ee..7cb8cef 100644 --- a/src/components/auth/EventAuth.ts +++ b/src/components/auth/EventAuth.ts @@ -1202,6 +1202,7 @@ export class EventAuth { const fileUrl = this.pb.files.getURL(event, file); const fileName = this.getFileNameFromUrl(file); const fileExt = fileName.split('.').pop()?.toLowerCase() || ''; + const nameWithoutExt = fileName.substring(0, fileName.lastIndexOf('.')); const fileItem = document.createElement("div"); fileItem.className = "bg-base-200 rounded-lg overflow-hidden"; @@ -1214,12 +1215,6 @@ export class EventAuth { ${fileName} `; - } else if (fileExt === 'pdf') { - previewHtml = ` -
- -
- `; } else { // For other file types, show an icon based on type const iconHtml = fileExt === 'txt' || fileExt === 'md' @@ -1239,23 +1234,26 @@ export class EventAuth { fileItem.innerHTML = ` ${previewHtml} -
-
- ${fileName} -
-
- - - - - - - -
+
+

+ ${nameWithoutExt} + ${fileExt} +

+
+
+ + + + + + Open + +
`; @@ -1263,7 +1261,7 @@ export class EventAuth { const deleteButton = fileItem.querySelector('.text-error'); if (deleteButton) { deleteButton.addEventListener('click', async (e) => { - e.preventDefault(); // Prevent any form submission + e.preventDefault(); if (confirm('Are you sure you want to remove this file?')) { try { const fileToRemove = deleteButton.getAttribute('data-file'); @@ -1307,14 +1305,14 @@ export class EventAuth { } } - private async handleViewFiles(eventId: string) { + private async handleViewFiles(eventId: string): Promise { try { - const event = await this.pb.collection("events").getOne(eventId); + const event = await this.pb.collection("events").getOne(eventId); // Create and show modal const modal = document.createElement("dialog"); modal.className = "modal"; - modal.innerHTML = ` + const modalContent = `