Sidebar: fold each module's pages

A chevron beside each module folds or unfolds its pages. The current
module is always open; the others keep the state you left them in; a
folded module shows its pages' counts added up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-22 15:27:22 -07:00
co-authored by Claude Opus 5.5
parent 9ca09c1ffa
commit 2a605ac265
4 changed files with 59 additions and 6 deletions
+10
View File
@@ -454,3 +454,13 @@ details.inline-details form { margin-top: 0.5rem; min-width: 18rem; }
.button.small { padding: 0.28rem 0.75rem; font-size: 0.82rem; }
input[type="color"] { height: 2.6rem; padding: 0.25rem; cursor: pointer; }
/* Collapsible module menus in the sidebar (app.js shows the toggles). */
.nav-row { display: flex; align-items: center; gap: 2px; }
.nav-row > a { flex: 1; min-width: 0; }
.nav .nav-toggle { background: transparent; border: 0; box-shadow: none; color: hsl(var(--muted-foreground)); padding: 0.3rem 0.35rem; min-height: 0; border-radius: var(--radius); cursor: pointer; line-height: 0; }
.nav .nav-toggle:hover { background: hsl(var(--accent) / 0.6); color: hsl(var(--foreground)); transform: none; }
.nav .nav-toggle .icon { width: 1rem; height: 1rem; transition: transform var(--fast); }
.nav-row.collapsed .nav-toggle .icon { transform: rotate(-90deg); }
.nav-sum { margin-left: auto; }
.nav-row:not(.collapsed) .nav-sum { display: none; }
.nav .nav-toggle:active { transform: none; }
+33
View File
@@ -137,4 +137,37 @@
});
document.addEventListener("DOMContentLoaded", syncProvider);
// Sidebar: each module's pages fold under a toggle. The module you're in
// is always open; the others stay as you last left them (closed at
// first). A folded module shows the sum of its pages' counts.
(function () {
var KEY = "supermarket.nav";
var state = {};
try { state = JSON.parse(localStorage.getItem(KEY)) || {}; } catch (e) {}
function set(sub, btn, open) {
sub.hidden = !open;
btn.setAttribute("aria-expanded", open ? "true" : "false");
btn.closest(".nav-row").classList.toggle("collapsed", !open);
}
document.querySelectorAll(".subnav[data-subnav]").forEach(function (sub) {
var btn = document.querySelector('.nav-toggle[aria-controls="' + sub.id + '"]');
if (!btn) return;
btn.hidden = false;
var sum = 0;
sub.querySelectorAll(".count-badge").forEach(function (b) { sum += parseInt(b.textContent, 10) || 0; });
var total = btn.closest(".nav-row").querySelector(".nav-sum");
if (total && sum > 0) {
total.textContent = sum;
total.title = sum + " waiting";
total.hidden = false;
}
set(sub, btn, sub.hasAttribute("data-current") || state[sub.dataset.subnav] === true);
btn.addEventListener("click", function () {
var open = sub.hidden;
set(sub, btn, open);
state[sub.dataset.subnav] = open;
try { localStorage.setItem(KEY, JSON.stringify(state)); } catch (e) {}
});
});
})();
})();