From aab3d7269a4e0d28317da6b246f4f85e6f7c20c7 Mon Sep 17 00:00:00 2001 From: FunnyPocketBook Date: Wed, 22 Jan 2025 22:52:12 +0100 Subject: [PATCH] fix: clear checkboxes on new search query (#66) This PR addresses an issue where the "download selected" functionality behaves unexpectedly. If a user makes a selection of books to download, performs a new search without clearing the previous selection, and selects new books, clicking "download selected" would still include the books from the prior selection. This causes the "download selected" button to fail, as the books from the previous selection are no longer available. A potential enhancement could allow users to select books across multiple searches and download them collectively. This could be achieved by creating a dedicated section in the UI to track and display the currently selected books. This feature might go well with a broader UI overhaul, as has been suggested in some issues - maybe after your CF bypass rewrite? Co-authored-by: CaliBrain --- static/js/main.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/static/js/main.js b/static/js/main.js index e4a2947..cc138db 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -221,7 +221,11 @@ document.addEventListener('DOMContentLoaded', () => { utils.fetchJson(`${API_ENDPOINTS.download}?id=${encodeURIComponent(bookId)}`) ); - // Uncheck all selected checkboxes + this.clearAllCheckboxes(); + modal.close(); + }, + + clearAllCheckboxes() { selectedBooks.forEach((bookId) => { const checkbox = document.getElementById(`book-${bookId}`); if (checkbox) checkbox.checked = false; @@ -232,13 +236,13 @@ document.addEventListener('DOMContentLoaded', () => { selectedBooks.clear(); utils.updateDownloadSelectedButton(); - modal.close(); } }; // Search Functions const search = { async performSearch(query) { + utils.clearAllCheckboxes(); if (STATE.isSearching) return; try {