Skip to content

Commit a2e1afa

Browse files
davila7claude
andcommitted
fix(sidebar): load component counts independently from page components
The sidebar counts depended on ComponentGrid or page-specific scripts to emit a custom event. Pages without those (component detail, trending, jobs) never received counts. Now the sidebar fetches /components.json directly on load. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent d37c578 commit a2e1afa

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

dashboard/src/components/Sidebar.astro

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,15 +233,31 @@ function isActive(path: string): boolean {
233233

234234
window.addEventListener('popstate', updateSidebarActive);
235235

236-
// Listen for component counts from React grid
237-
window.addEventListener('component-counts', ((e: CustomEvent) => {
238-
const counts = e.detail as Record<string, number>;
236+
// Load component counts directly — no dependency on page components
237+
function applyCounts(counts: Record<string, number>) {
239238
document.querySelectorAll('.sidebar-nav-count').forEach((el) => {
240239
const type = (el as HTMLElement).dataset.countType;
241240
if (type && counts[type]) {
242241
el.textContent = String(counts[type]);
243242
}
244243
});
244+
}
245+
246+
// Fetch counts on load
247+
fetch('/components.json')
248+
.then((r) => r.json())
249+
.then((data: Record<string, unknown>) => {
250+
const counts: Record<string, number> = {};
251+
for (const type of Object.keys(data)) {
252+
if (Array.isArray(data[type])) counts[type] = (data[type] as unknown[]).length;
253+
}
254+
applyCounts(counts);
255+
})
256+
.catch(() => {});
257+
258+
// Also listen for counts from React grid (may arrive with more accurate data)
259+
window.addEventListener('component-counts', ((e: CustomEvent) => {
260+
applyCounts(e.detail as Record<string, number>);
245261
}) as EventListener);
246262

247263
// Custom tooltip functionality

0 commit comments

Comments
 (0)