Compare commits

...

2 Commits

Author SHA1 Message Date
Tom Moor e2a0f1bc44 Simplify membershipType logic 2024-12-05 20:50:05 -05:00
Tom Moor d1931de805 fix: Use sidebarContext in header breadcrumbs 2024-12-05 20:40:44 -05:00
3 changed files with 18 additions and 29 deletions
+12 -9
View File
@@ -8,15 +8,11 @@ import Document from "~/models/Document";
import Breadcrumb from "~/components/Breadcrumb";
import Icon from "~/components/Icon";
import CollectionIcon from "~/components/Icons/CollectionIcon";
import { useLocationSidebarContext } from "~/hooks/useLocationSidebarContext";
import usePolicy from "~/hooks/usePolicy";
import useStores from "~/hooks/useStores";
import { MenuInternalLink } from "~/types";
import {
archivePath,
collectionPath,
settingsPath,
trashPath,
} from "~/utils/routeHelpers";
import { archivePath, settingsPath, trashPath } from "~/utils/routeHelpers";
type Props = {
children?: React.ReactNode;
@@ -64,6 +60,7 @@ function DocumentBreadcrumb(
const { collections } = useStores();
const { t } = useTranslation();
const category = useCategory(document);
const sidebarContext = useLocationSidebarContext();
const collection = document.collectionId
? collections.get(document.collectionId)
: undefined;
@@ -80,7 +77,10 @@ function DocumentBreadcrumb(
type: "route",
title: collection.name,
icon: <CollectionIcon collection={collection} expanded />,
to: collectionPath(collection.path),
to: {
pathname: collection.path,
state: { sidebarContext },
},
};
} else if (document.isCollectionDeleted) {
collectionNode = {
@@ -114,11 +114,14 @@ function DocumentBreadcrumb(
) : (
node.title
),
to: node.url,
to: {
pathname: node.url,
state: { sidebarContext },
},
});
});
return output;
}, [path, category, collectionNode]);
}, [path, category, sidebarContext, collectionNode]);
if (!collections.isLoaded) {
return null;
@@ -40,18 +40,18 @@ export const determineSidebarContext = ({
: starredSidebarContext(document.collectionId!);
}
const membershipType = document.membershipType;
if (membershipType === "document") {
if (document.collection) {
return "collections";
} else if (
user.documentMemberships.find((m) => m.documentId === document.id)
) {
return "shared";
} else if (membershipType === "group") {
} else {
const group = user.groupsWithDocumentMemberships.find(
(g) => !!g.documentMemberships.find((m) => m.documentId === document.id)
);
return groupSidebarContext(group?.id ?? "");
}
return "collections";
};
export default SidebarContext;
-14
View File
@@ -426,20 +426,6 @@ export default class Document extends ArchivableModel {
return this.title || i18n.t("Untitled");
}
@computed
get membershipType(): "collection" | "document" | "group" {
if (this.collection) {
return "collection";
}
const hasDocumentMembership =
this.store.rootStore.auth.user?.documentMemberships.find(
(m) => m.documentId === this.id
) ?? false;
return hasDocumentMembership ? "document" : "group";
}
@action
updateTasks(total: number, completed: number) {
if (total !== this.tasks.total || completed !== this.tasks.completed) {