Skip to content

Commit f385829

Browse files
committed
feat: add fallback state for empty table of contents
1 parent c89a28f commit f385829

File tree

1 file changed

+30
-22
lines changed

1 file changed

+30
-22
lines changed

apps/website/app/[locale]/blog/[slug]/components/TableOfContents.tsx

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -47,29 +47,37 @@ export function TableOfContents() {
4747
<nav className="space-y-2 text-sm">
4848
<p className="font-medium mb-4">Table of Contents</p>
4949
<ul className="space-y-2">
50-
{headings.map((heading) => (
51-
<li
52-
key={heading.id}
53-
style={{ paddingLeft: `${(heading.level - 1) * 1}rem` }}
54-
>
55-
<a
56-
href={`#${heading.id}`}
57-
onClick={(e) => {
58-
e.preventDefault();
59-
document.getElementById(heading.id)?.scrollIntoView({
60-
behavior: "smooth",
61-
});
62-
}}
63-
className={`hover:text-primary transition-colors block ${
64-
activeId === heading.id
65-
? "text-primary font-medium"
66-
: "text-muted-foreground"
67-
}`}
68-
>
69-
{heading.text}
70-
</a>
50+
{headings.length > 0 ? (
51+
<>
52+
{headings.map((heading) => (
53+
<li
54+
key={heading.id}
55+
style={{ paddingLeft: `${(heading.level - 1) * 1}rem` }}
56+
>
57+
<a
58+
href={`#${heading.id}`}
59+
onClick={(e) => {
60+
e.preventDefault();
61+
document.getElementById(heading.id)?.scrollIntoView({
62+
behavior: "smooth",
63+
});
64+
}}
65+
className={`hover:text-primary transition-colors block ${
66+
activeId === heading.id
67+
? "text-primary font-medium"
68+
: "text-muted-foreground"
69+
}`}
70+
>
71+
{heading.text}
72+
</a>
73+
</li>
74+
))}
75+
</>
76+
) : (
77+
<li>
78+
<p className="text-muted-foreground">No headings found</p>
7179
</li>
72-
))}
80+
)}
7381
</ul>
7482
</nav>
7583
);

0 commit comments

Comments
 (0)