diff --git a/app.py b/app.py index 41cd39d..f207c90 100644 --- a/app.py +++ b/app.py @@ -1952,7 +1952,7 @@ def suggest_products(): @app.route("/all_products") def all_products(): sort = request.args.get("sort", "popularity") - limit = request.args.get("limit", type=int) or 100 + limit = request.args.get("limit", type=int) or 50 offset = request.args.get("offset", type=int) or 0 rows = db.session.query(Item.name, Item.list_id).distinct().all() diff --git a/static/js/mass_add.js b/static/js/mass_add.js index 89b2f01..f8e29ac 100644 --- a/static/js/mass_add.js +++ b/static/js/mass_add.js @@ -6,13 +6,7 @@ document.addEventListener('DOMContentLoaded', function () { const modalBody = modal?.querySelector('.modal-body'); function normalize(str) { - return str - ? str.normalize("NFD") - .replace(/[\u0300-\u036f]/g, "") - .replace(/\s+/g, ' ') - .trim() - .toLowerCase() - : ''; + return str?.trim().toLowerCase() || ''; } let sortMode = 'popularity'; @@ -69,7 +63,7 @@ document.addEventListener('DOMContentLoaded', function () { try { const res = await fetch(`/all_products?sort=${sortMode}&limit=${limit}&offset=${offset}`); const data = await res.json(); - const products = data.products || data.allproducts || []; + const products = data.products || []; if (products.length < limit) reachedEnd = true; allProducts = reset ? products : allProducts.concat(products); @@ -114,12 +108,23 @@ document.addEventListener('DOMContentLoaded', function () { function renderProducts(products) { addedProducts = getAlreadyAddedProducts(); - products.forEach(name => { - if (typeof name === "object" && name.name) name = name.name; + + const existingNames = new Set(); + document.querySelectorAll('#mass-add-list li').forEach(li => { + const name = li.querySelector('span')?.textContent; + if (name) existingNames.add(normalize(name)); + }); + + products.forEach(product => { + const name = typeof product === "object" ? product.name : product; + const normName = normalize(name); + if (existingNames.has(normName)) return; + existingNames.add(normName); + const li = document.createElement('li'); li.className = 'list-group-item d-flex justify-content-between align-items-center bg-dark text-light'; - if (addedProducts.has(normalize(name))) { + if (addedProducts.has(normName)) { const nameSpan = document.createElement('span'); nameSpan.textContent = name; li.appendChild(nameSpan);