Private
Public Access
Show each tag's total unread count and remember collapsed sections
Closes gitea#24: the sidebar's per-feed unread counts were already computed by sidebar() (apps.core.context_processors); each tag group's total is now the sum of its own feeds' counts (a feed can carry more than one tag, so this reuses the same per-feed data rather than a second query) and renders next to the tag name like a feed's own count. Closes gitea#25: each sidebar <details> section (one per tag, plus "Untagged") now carries a stable data-sidebar-key, and static/js/sidebar-state.js remembers which ones are collapsed in localStorage — this isn't a SPA, so every click re-renders the sidebar server-side, and previously every section reset back to expanded on the next page load. Per-browser, same pattern as theme.js/theme-init.js, not synced across devices/accounts. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
9439f9cc59
commit
e760eeda1d
7 files changed
+186
-6
No files matched your search
@@ -299,6 +299,16 @@ form p {
|
||||
letter-spacing: 0.04em;
|
||||
}
|
||||
|
||||
/* An inner wrapper, not `summary` itself — `summary`'s native disclosure
|
||||
triangle only renders with its default `display: list-item`, so the
|
||||
flex layout for the tag name + unread count lives one level in. */
|
||||
.sidebar-tag-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 0.4rem;
|
||||
}
|
||||
|
||||
.sidebar-tag-link {
|
||||
display: inline-block;
|
||||
padding: 0.15rem 0.4rem;
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
(function () {
|
||||
// Remembers which sidebar <details> sections (one per tag, plus
|
||||
// "Untagged" — see templates/core/_sidebar.html's data-sidebar-key)
|
||||
// the user has collapsed, so a full page navigation (this isn't an
|
||||
// SPA — every click re-renders the sidebar server-side) doesn't keep
|
||||
// snapping them back open. Per-browser via localStorage, same pattern
|
||||
// as theme.js/theme-init.js — not synced across devices/accounts.
|
||||
var STORAGE_KEY = "evection-sidebar-collapsed";
|
||||
|
||||
function readCollapsed() {
|
||||
try {
|
||||
var raw = localStorage.getItem(STORAGE_KEY);
|
||||
return raw ? JSON.parse(raw) : [];
|
||||
} catch (e) {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function writeCollapsed(keys) {
|
||||
try {
|
||||
localStorage.setItem(STORAGE_KEY, JSON.stringify(keys));
|
||||
} catch (e) {
|
||||
/* localStorage unavailable (private mode, etc.) — state just won't persist */
|
||||
}
|
||||
}
|
||||
|
||||
var collapsed = readCollapsed();
|
||||
|
||||
document.querySelectorAll(".sidebar-section[data-sidebar-key]").forEach(function (details) {
|
||||
var key = details.dataset.sidebarKey;
|
||||
if (collapsed.indexOf(key) !== -1) {
|
||||
details.open = false;
|
||||
}
|
||||
|
||||
details.addEventListener("toggle", function () {
|
||||
var current = readCollapsed();
|
||||
var index = current.indexOf(key);
|
||||
if (details.open) {
|
||||
if (index !== -1) current.splice(index, 1);
|
||||
} else if (index === -1) {
|
||||
current.push(key);
|
||||
}
|
||||
writeCollapsed(current);
|
||||
});
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user