fix: Error opening folded document breadcrumb (from ts migration)
This commit is contained in:
@@ -6,14 +6,8 @@ import Flex from "~/components/Flex";
|
|||||||
import BreadcrumbMenu from "~/menus/BreadcrumbMenu";
|
import BreadcrumbMenu from "~/menus/BreadcrumbMenu";
|
||||||
import { MenuInternalLink } from "~/types";
|
import { MenuInternalLink } from "~/types";
|
||||||
|
|
||||||
export type Crumb = {
|
|
||||||
title: React.ReactNode;
|
|
||||||
icon?: React.ReactNode;
|
|
||||||
to?: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
items: Crumb[];
|
items: MenuInternalLink[];
|
||||||
max?: number;
|
max?: number;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
highlightFirstItem?: boolean;
|
highlightFirstItem?: boolean;
|
||||||
@@ -21,7 +15,7 @@ type Props = {
|
|||||||
|
|
||||||
function Breadcrumb({ items, highlightFirstItem, children, max = 2 }: Props) {
|
function Breadcrumb({ items, highlightFirstItem, children, max = 2 }: Props) {
|
||||||
const totalItems = items.length;
|
const totalItems = items.length;
|
||||||
const topLevelItems: Crumb[] = [...items];
|
const topLevelItems: MenuInternalLink[] = [...items];
|
||||||
let overflowItems;
|
let overflowItems;
|
||||||
|
|
||||||
// chop middle breadcrumbs and present a "..." menu instead
|
// chop middle breadcrumbs and present a "..." menu instead
|
||||||
@@ -30,6 +24,8 @@ function Breadcrumb({ items, highlightFirstItem, children, max = 2 }: Props) {
|
|||||||
overflowItems = topLevelItems.splice(halfMax, totalItems - max);
|
overflowItems = topLevelItems.splice(halfMax, totalItems - max);
|
||||||
|
|
||||||
topLevelItems.splice(halfMax, 0, {
|
topLevelItems.splice(halfMax, 0, {
|
||||||
|
to: "",
|
||||||
|
type: "route",
|
||||||
title: <BreadcrumbMenu items={overflowItems as MenuInternalLink[]} />,
|
title: <BreadcrumbMenu items={overflowItems as MenuInternalLink[]} />,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,10 +10,10 @@ import * as React from "react";
|
|||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import styled from "styled-components";
|
import styled from "styled-components";
|
||||||
import Document from "~/models/Document";
|
import Document from "~/models/Document";
|
||||||
import Breadcrumb, { Crumb } from "~/components/Breadcrumb";
|
import Breadcrumb from "~/components/Breadcrumb";
|
||||||
import CollectionIcon from "~/components/CollectionIcon";
|
import CollectionIcon from "~/components/CollectionIcon";
|
||||||
import useStores from "~/hooks/useStores";
|
import useStores from "~/hooks/useStores";
|
||||||
import { NavigationNode } from "~/types";
|
import { MenuInternalLink, NavigationNode } from "~/types";
|
||||||
import { collectionUrl } from "~/utils/routeHelpers";
|
import { collectionUrl } from "~/utils/routeHelpers";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
@@ -22,11 +22,12 @@ type Props = {
|
|||||||
onlyText?: boolean;
|
onlyText?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
function useCategory(document: Document) {
|
function useCategory(document: Document): MenuInternalLink | null {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
if (document.isDeleted) {
|
if (document.isDeleted) {
|
||||||
return {
|
return {
|
||||||
|
type: "route",
|
||||||
icon: <TrashIcon color="currentColor" />,
|
icon: <TrashIcon color="currentColor" />,
|
||||||
title: t("Trash"),
|
title: t("Trash"),
|
||||||
to: "/trash",
|
to: "/trash",
|
||||||
@@ -35,6 +36,7 @@ function useCategory(document: Document) {
|
|||||||
|
|
||||||
if (document.isArchived) {
|
if (document.isArchived) {
|
||||||
return {
|
return {
|
||||||
|
type: "route",
|
||||||
icon: <ArchiveIcon color="currentColor" />,
|
icon: <ArchiveIcon color="currentColor" />,
|
||||||
title: t("Archive"),
|
title: t("Archive"),
|
||||||
to: "/archive",
|
to: "/archive",
|
||||||
@@ -43,6 +45,7 @@ function useCategory(document: Document) {
|
|||||||
|
|
||||||
if (document.isDraft) {
|
if (document.isDraft) {
|
||||||
return {
|
return {
|
||||||
|
type: "route",
|
||||||
icon: <EditIcon color="currentColor" />,
|
icon: <EditIcon color="currentColor" />,
|
||||||
title: t("Drafts"),
|
title: t("Drafts"),
|
||||||
to: "/drafts",
|
to: "/drafts",
|
||||||
@@ -51,6 +54,7 @@ function useCategory(document: Document) {
|
|||||||
|
|
||||||
if (document.isTemplate) {
|
if (document.isTemplate) {
|
||||||
return {
|
return {
|
||||||
|
type: "route",
|
||||||
icon: <ShapesIcon color="currentColor" />,
|
icon: <ShapesIcon color="currentColor" />,
|
||||||
title: t("Templates"),
|
title: t("Templates"),
|
||||||
to: "/templates",
|
to: "/templates",
|
||||||
@@ -66,16 +70,18 @@ const DocumentBreadcrumb = ({ document, children, onlyText }: Props) => {
|
|||||||
const category = useCategory(document);
|
const category = useCategory(document);
|
||||||
const collection = collections.get(document.collectionId);
|
const collection = collections.get(document.collectionId);
|
||||||
|
|
||||||
let collectionNode: Crumb;
|
let collectionNode: MenuInternalLink;
|
||||||
|
|
||||||
if (collection) {
|
if (collection) {
|
||||||
collectionNode = {
|
collectionNode = {
|
||||||
|
type: "route",
|
||||||
title: collection.name,
|
title: collection.name,
|
||||||
icon: <CollectionIcon collection={collection} expanded />,
|
icon: <CollectionIcon collection={collection} expanded />,
|
||||||
to: collectionUrl(collection.url),
|
to: collectionUrl(collection.url),
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
collectionNode = {
|
collectionNode = {
|
||||||
|
type: "route",
|
||||||
title: t("Deleted Collection"),
|
title: t("Deleted Collection"),
|
||||||
icon: undefined,
|
icon: undefined,
|
||||||
to: collectionUrl("deleted-collection"),
|
to: collectionUrl("deleted-collection"),
|
||||||
@@ -88,7 +94,7 @@ const DocumentBreadcrumb = ({ document, children, onlyText }: Props) => {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const items = React.useMemo(() => {
|
const items = React.useMemo(() => {
|
||||||
const output: Crumb[] = [];
|
const output = [];
|
||||||
|
|
||||||
if (category) {
|
if (category) {
|
||||||
output.push(category);
|
output.push(category);
|
||||||
@@ -96,10 +102,11 @@ const DocumentBreadcrumb = ({ document, children, onlyText }: Props) => {
|
|||||||
|
|
||||||
output.push(collectionNode);
|
output.push(collectionNode);
|
||||||
|
|
||||||
path.forEach((p: NavigationNode) => {
|
path.forEach((node: NavigationNode) => {
|
||||||
output.push({
|
output.push({
|
||||||
title: p.title,
|
type: "route",
|
||||||
to: p.url,
|
title: node.title,
|
||||||
|
to: node.url,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
return output;
|
return output;
|
||||||
@@ -113,10 +120,10 @@ const DocumentBreadcrumb = ({ document, children, onlyText }: Props) => {
|
|||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
{collection?.name}
|
{collection?.name}
|
||||||
{path.map((n: any) => (
|
{path.map((node: NavigationNode) => (
|
||||||
<React.Fragment key={n.id}>
|
<React.Fragment key={node.id}>
|
||||||
<SmallSlash />
|
<SmallSlash />
|
||||||
{n.title}
|
{node.title}
|
||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
))}
|
))}
|
||||||
</>
|
</>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as React from "react";
|
import * as React from "react";
|
||||||
import Breadcrumb from "~/components/Breadcrumb";
|
import Breadcrumb from "~/components/Breadcrumb";
|
||||||
import { NavigationNode } from "~/types";
|
import { MenuInternalLink, NavigationNode } from "~/types";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
documentId: string;
|
documentId: string;
|
||||||
@@ -44,12 +44,12 @@ const PublicBreadcrumb = ({
|
|||||||
sharedTree,
|
sharedTree,
|
||||||
children,
|
children,
|
||||||
}: Props) => {
|
}: Props) => {
|
||||||
const items = React.useMemo(
|
const items: MenuInternalLink[] = React.useMemo(
|
||||||
() =>
|
() =>
|
||||||
pathToDocument(sharedTree, documentId)
|
pathToDocument(sharedTree, documentId)
|
||||||
.slice(0, -1)
|
.slice(0, -1)
|
||||||
.map((item) => {
|
.map((item) => {
|
||||||
return { ...item, to: `/share/${shareId}${item.url}` };
|
return { ...item, type: "route", to: `/share/${shareId}${item.url}` };
|
||||||
}),
|
}),
|
||||||
[sharedTree, shareId, documentId]
|
[sharedTree, shareId, documentId]
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user