From b9dba85a57773f8d749b98780ad3bdfdaab6367e Mon Sep 17 00:00:00 2001 From: 01zulfi <85733202+01zulfi@users.noreply.github.com> Date: Fri, 14 Mar 2025 11:52:53 +0500 Subject: [PATCH] web: restore notebook crumbs (#7765) Signed-off-by: 01zulfi <85733202+01zulfi@users.noreply.github.com> --- apps/web/src/components/notebook-header.tsx | 132 ++++++++++++++++++-- 1 file changed, 121 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/notebook-header.tsx b/apps/web/src/components/notebook-header.tsx index 39d99c84c..83d959ff0 100644 --- a/apps/web/src/components/notebook-header.tsx +++ b/apps/web/src/components/notebook-header.tsx @@ -17,29 +17,35 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -import { useEffect, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { useStore as useAppStore } from "../stores/app-store"; -import { hashNavigate } from "../navigation"; +import { hashNavigate, navigate } from "../navigation"; import { Button, Flex, Text } from "@theme-ui/components"; -import { Edit, RemoveShortcutLink, ShortcutLink } from "./icons"; +import { + ChevronRight, + Edit, + MoreHorizontal, + Notebook2, + RemoveShortcutLink, + ShortcutLink +} from "./icons"; import { useStore as useNotebookStore } from "../stores/notebook-store"; import { db } from "../common/db"; import { getFormattedDate } from "@notesnook/common"; import { strings } from "@notesnook/intl"; import { Notebook } from "@notesnook/core"; import { TITLE_BAR_HEIGHT } from "./title-bar"; +import { Menu } from "../hooks/use-menu"; export function NotebookHeader(props: { notebook: Notebook; totalNotes?: number; }) { - // const moreCrumbsRef = useRef(null); const notebooks = useNotebookStore((store) => store.notebooks); const [notebook, setNotebook] = useState( props.notebook ); const [totalNotes, setTotalNotes] = useState(props.totalNotes); - // const [crumbs, setCrumbs] = useState<{ id: string; title: string }[]>([]); const [isShortcut, setIsShortcut] = useState(false); const shortcuts = useAppStore((store) => store.shortcuts); const addToShortcuts = useAppStore((store) => store.addToShortcuts); @@ -63,12 +69,6 @@ export function NotebookHeader(props: { else setTotalNotes(props.totalNotes); }, [props.notebook, props.totalNotes]); - // useEffect(() => { - // (async function () { - // setCrumbs(await db.notebooks.breadcrumbs(context.id)); - // })(); - // }, [context.id]); - if (!notebook) return null; const { title, description, dateEdited } = notebook; @@ -83,6 +83,7 @@ export function NotebookHeader(props: { borderBottom: "1px solid var(--border)" }} > + {getFormattedDate(dateEdited, "date")} @@ -134,3 +135,112 @@ export function NotebookHeader(props: { ); } + +function NotebookCrumbs(props: { notebook: Notebook }) { + const moreCrumbsRef = useRef(null); + const [crumbs, setCrumbs] = useState<{ id: string; title: string }[]>([]); + + useEffect(() => { + (async function () { + setCrumbs(await db.notebooks.breadcrumbs(props.notebook.id)); + })(); + }, [props.notebook]); + + if (crumbs.length < 2) { + return null; + } + + return ( + + navigateCrumb(crumbs[0]?.id)} + text={crumbs[0]?.title} + /> + + {crumbs.length > 3 && ( + <> + + + + )} + {crumbs.slice(crumbs.length > 2 ? -2 : -1).map((crumb, index, array) => ( + <> + navigateCrumb(crumb.id)} + text={crumb.title} + /> + {index === array.length - 1 ? null : ( + + )} + + ))} + + ); +} + +function CrumbText(props: { text: string; onClick: () => void }) { + return ( + + {props.text} + + ); +} + +function navigateCrumb(notebookId: string) { + navigate(`/notebooks/${notebookId}`); +}