Add Recent filter to show 10 most recently added items
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 <noreply@anthropic.com>
This commit is contained in:
19
index.html
19
index.html
@@ -662,6 +662,7 @@
|
||||
<button class="nav-tab" data-filter="in-stock">In Stock</button>
|
||||
<button class="nav-tab" data-filter="out">Out of Stock</button>
|
||||
<button class="nav-tab" data-filter="spices">Spices</button>
|
||||
<button class="nav-tab" data-filter="recent">Recent</button>
|
||||
<button class="nav-tab" data-filter="qr">QR Code</button>
|
||||
</div>
|
||||
|
||||
@@ -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 = `
|
||||
|
||||
Reference in New Issue
Block a user