Skip to content

Build your personal knowledge base with Trilium Notes

feat(breadcrumb): get breadcrumb to render

Elian Dorand02ec47d7710
diff --git a/apps/client/src/layouts/desktop_layout.tsx b/apps/client/src/layouts/desktop_layout.tsx
index 90b8566e9f..0347acf1e4 100644
--- a/apps/client/src/layouts/desktop_layout.tsx
+++ b/apps/client/src/layouts/desktop_layout.tsx
@@ -44,6 +44,7 @@ import NoteDetail from "../widgets/NoteDetail.jsx";
import PromotedAttributes from "../widgets/PromotedAttributes.jsx";
import SpacerWidget from "../widgets/launch_bar/SpacerWidget.jsx";
import LauncherContainer from "../widgets/launch_bar/LauncherContainer.jsx";
+import Breadcrumb from "../widgets/Breadcrumb.jsx";
export default class DesktopLayout {
@@ -122,6 +123,7 @@ export default class DesktopLayout {
.css("min-height", "30px")
.css("align-items", "center")
.cssBlock(".breadcrumb-row > * { margin: 5px; }")
+ .child(<Breadcrumb />)
.child(<SpacerWidget baseSize={0} growthFactor={1} />)
.child(<MovePaneButton direction="left" />)
.child(<MovePaneButton direction="right" />)
diff --git a/apps/client/src/widgets/Breadcrumb.css b/apps/client/src/widgets/Breadcrumb.css
new file mode 100644
index 0000000000..fe081ee3fc
--- /dev/null
+++ b/apps/client/src/widgets/Breadcrumb.css
@@ -0,0 +1,4 @@
+.component.breadcrumb {
+ contain: none;
+ margin: 0 10px;
+}
diff --git a/apps/client/src/widgets/Breadcrumb.tsx b/apps/client/src/widgets/Breadcrumb.tsx
new file mode 100644
index 0000000000..0dd3068680
--- /dev/null
+++ b/apps/client/src/widgets/Breadcrumb.tsx
@@ -0,0 +1,36 @@
+import "./Breadcrumb.css";
+import { useNoteContext } from "./react/hooks";
+import NoteLink from "./react/NoteLink";
+import { joinElements } from "./react/react_utils";
+
+export default function Breadcrumb() {
+ const { noteContext } = useNoteContext();
+ const notePath = buildNotePaths(noteContext?.notePathArray);
+ console.log("Render with ", notePath);
+
+ return (
+ <div className="breadcrumb">
+ {joinElements(notePath.map(item => (
+ <BreadcrumbItem key={item} notePath={item} />
+ )), <>&nbsp;›&nbsp;</>)}
+ </div>
+ )
+}
+
+function BreadcrumbItem({ notePath }: { notePath: string }) {
+ return (
+ <NoteLink notePath={notePath} />
+ )
+}
+
+function buildNotePaths(notePathArray: string[] | undefined) {
+ if (!notePathArray) return [];
+
+ let prefix = "";
+ const output: string[] = [];
+ for (const notePath of notePathArray) {
+ output.push(`${prefix}${notePath}`);
+ prefix += `${notePath}/`;
+ }
+ return output;
+}
diff --git a/apps/client/src/widgets/react/react_utils.tsx b/apps/client/src/widgets/react/react_utils.tsx
index 468a0e73ef..3bbce9066f 100644
--- a/apps/client/src/widgets/react/react_utils.tsx
+++ b/apps/client/src/widgets/react/react_utils.tsx
@@ -44,7 +44,7 @@ export function disposeReactWidget(container: Element) {
render(null, container);
}
-export function joinElements(components: ComponentChild[] | undefined, separator = ", ") {
+export function joinElements(components: ComponentChild[] | undefined, separator: ComponentChild = ", ") {
if (!components) return <></>;
const joinedComponents: ComponentChild[] = [];