Skip to content

Build your personal knowledge base with Trilium Notes

feat(right_pane_widget): handle zero headings

Elian Doran6da42fac20c7
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index fc3bd58794..458ea6b0c1 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1796,7 +1796,8 @@
},
"toc": {
"table_of_contents": "Table of Contents",
- "options": "Options"
+ "options": "Options",
+ "no_headings": "No headings."
},
"watched_file_update_status": {
"file_last_modified": "File <code class=\"file-path\"></code> has been last modified on <span class=\"file-last-modified\"></span>.",
diff --git a/apps/client/src/widgets/sidebar/TableOfContents.tsx b/apps/client/src/widgets/sidebar/TableOfContents.tsx
index 48c5217e99..b58c2d8c4a 100644
--- a/apps/client/src/widgets/sidebar/TableOfContents.tsx
+++ b/apps/client/src/widgets/sidebar/TableOfContents.tsx
@@ -40,9 +40,13 @@ function AbstractTableOfContents<T extends RawHeading>({ headings, scrollToHeadi
const nestedHeadings = buildHeadingTree(headings);
return (
<span className="toc">
- <ol>
- {nestedHeadings.map(heading => <TableOfContentsHeading key={heading.id} heading={heading} scrollToHeading={scrollToHeading} />)}
- </ol>
+ {nestedHeadings.length > 0 ? (
+ <ol>
+ {nestedHeadings.map(heading => <TableOfContentsHeading key={heading.id} heading={heading} scrollToHeading={scrollToHeading} />)}
+ </ol>
+ ) : (
+ <div className="no-headings">{t("toc.no_headings")}</div>
+ )}
</span>
);
}