From e2a0f1bc44d3992994e571df6b77abbfa532fe9f Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Thu, 5 Dec 2024 20:50:05 -0500 Subject: [PATCH] Simplify membershipType logic --- .../Sidebar/components/SidebarContext.ts | 12 ++++++------ app/models/Document.ts | 14 -------------- 2 files changed, 6 insertions(+), 20 deletions(-) diff --git a/app/components/Sidebar/components/SidebarContext.ts b/app/components/Sidebar/components/SidebarContext.ts index 8bcbc874e8..379d746d68 100644 --- a/app/components/Sidebar/components/SidebarContext.ts +++ b/app/components/Sidebar/components/SidebarContext.ts @@ -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; diff --git a/app/models/Document.ts b/app/models/Document.ts index 7e1418ae3a..6c0a9736a7 100644 --- a/app/models/Document.ts +++ b/app/models/Document.ts @@ -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) {