From f39a9b0c5ae7d97109a081ece6e7b9c0961ddbef Mon Sep 17 00:00:00 2001 From: Eric Wagoner Date: Tue, 23 Dec 2025 23:13:11 -0500 Subject: [PATCH] Add Recent filter to show 10 most recently added items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sorts by ID descending (newest first) and limits to 10 items. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- index.html | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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 = `