From 5f00e88c687c05562954028bcacfc66874990f97 Mon Sep 17 00:00:00 2001 From: chark1es Date: Fri, 31 Jan 2025 23:28:55 -0800 Subject: [PATCH] fix file deletion --- src/components/auth/EventAuth.ts | 9 +++++---- src/components/profile/EventEditor.astro | 7 ++++++- src/components/reimbursement/Reimbursement.astro | 0 src/pages/reimbursement.astro | 7 +++++++ 4 files changed, 18 insertions(+), 5 deletions(-) create mode 100644 src/components/reimbursement/Reimbursement.astro create mode 100644 src/pages/reimbursement.astro diff --git a/src/components/auth/EventAuth.ts b/src/components/auth/EventAuth.ts index 6fa72cc..4b244d0 100644 --- a/src/components/auth/EventAuth.ts +++ b/src/components/auth/EventAuth.ts @@ -1183,13 +1183,14 @@ export class EventAuth { // Add delete handler const deleteButton = fileItem.querySelector('.text-error'); if (deleteButton) { - deleteButton.addEventListener('click', async () => { + deleteButton.addEventListener('click', async (e) => { + e.preventDefault(); // Prevent any form submission if (confirm('Are you sure you want to remove this file?')) { try { const fileToRemove = deleteButton.getAttribute('data-file'); if (!fileToRemove) throw new Error('File not found'); - // Get the current event data to ensure we have the latest state + // Get the current event data const currentEvent = await this.pb.collection('events').getOne(event.id); // Filter out the file to be removed @@ -1200,14 +1201,14 @@ export class EventAuth { files: updatedFiles }); - // Update the event.files array in memory + // Update the local event object event.files = updatedFiles; // Remove the file item from the UI fileItem.remove(); // If no files left, show the "No files" message - if (updatedFiles.length === 0) { + if (!event.files || event.files.length === 0) { currentFiles.innerHTML = 'No files'; } } catch (err) { diff --git a/src/components/profile/EventEditor.astro b/src/components/profile/EventEditor.astro index a37159f..dc2f2be 100644 --- a/src/components/profile/EventEditor.astro +++ b/src/components/profile/EventEditor.astro @@ -10,7 +10,12 @@ const { editor_title, form } = config.ui.tables.events;