diff --git a/index.html b/index.html index 03614f5..378fd58 100644 --- a/index.html +++ b/index.html @@ -662,6 +662,7 @@ + @@ -946,6 +947,7 @@ let filtered = inventory.filter(item => { const matchesSearch = item.name.toLowerCase().includes(searchTerm); const matchesFilter = currentFilter === 'all' || + currentFilter === 'recent' || (currentFilter === 'in-stock' && !item.outOfStock) || (currentFilter === 'out' && item.outOfStock) || (currentFilter === 'spices' && item.container.startsWith('spice-')); @@ -953,11 +955,18 @@ return matchesSearch && matchesFilter && matchesContainer; }); - // Sort: in-stock first, then alphabetically - filtered.sort((a, b) => { - if (a.outOfStock !== b.outOfStock) return a.outOfStock ? 1 : -1; - return a.name.localeCompare(b.name); - }); + // Sort based on filter + if (currentFilter === 'recent') { + // Sort by ID descending (newest first) and limit to 10 + filtered.sort((a, b) => b.id - a.id); + filtered = filtered.slice(0, 10); + } else { + // Sort: in-stock first, then alphabetically + filtered.sort((a, b) => { + if (a.outOfStock !== b.outOfStock) return a.outOfStock ? 1 : -1; + return a.name.localeCompare(b.name); + }); + } if (filtered.length === 0) { list.innerHTML = `