From 8f960620584fde655615cc8b3fb541a28a68d1e4 Mon Sep 17 00:00:00 2001 From: Drew Haven Date: Tue, 15 Jul 2025 10:09:53 -0700 Subject: [PATCH] Fixes bug with updating relationships when an item is added --- src/components/RelationshipList.tsx | 13 +++---------- src/components/documents/DocumentView.tsx | 8 ++------ src/components/documents/RelatedDocumentList.tsx | 2 -- src/context/document/DocumentContext.tsx | 2 ++ .../_app/_authenticated/campaigns.$campaignId.tsx | 10 ---------- 5 files changed, 7 insertions(+), 28 deletions(-) diff --git a/src/components/RelationshipList.tsx b/src/components/RelationshipList.tsx index 50da46d..b2de2f3 100644 --- a/src/components/RelationshipList.tsx +++ b/src/components/RelationshipList.tsx @@ -35,10 +35,6 @@ export function RelationshipList({ return ; } - const doc = docResult.value.doc; - - console.info("Rendering relationship list: ", relationshipType); - const relationshipResult = docResult.value.relationships[relationshipType]; const relationship = @@ -60,7 +56,6 @@ export function RelationshipList({ try { // Check for existing relationship if (relationship) { - console.debug("Adding to existing relationship", relationship.id); const updatedRelationship: Relationship = await pb .collection("relationships") .update(relationship.id, { @@ -68,11 +63,10 @@ export function RelationshipList({ }); dispatch({ type: "setRelationship", - docId: doc.id, + docId: root.id, relationship: updatedRelationship, }); } else { - console.debug("Creating new relationship"); const updatedRelationship: Relationship = await pb .collection("relationships") .create({ @@ -82,7 +76,7 @@ export function RelationshipList({ }); dispatch({ type: "setRelationship", - docId: doc.id, + docId: root.id, relationship: updatedRelationship, }); } @@ -99,7 +93,6 @@ export function RelationshipList({ try { if (relationship) { - console.debug("Removing from existing relationship", relationship.id); const updatedRelationship: Relationship = await pb .collection("relationships") .update(relationship.id, { @@ -107,7 +100,7 @@ export function RelationshipList({ }); dispatch({ type: "setRelationship", - docId: doc.id, + docId: root.id, relationship: updatedRelationship, }); } diff --git a/src/components/documents/DocumentView.tsx b/src/components/documents/DocumentView.tsx index e29b029..4c60ee8 100644 --- a/src/components/documents/DocumentView.tsx +++ b/src/components/documents/DocumentView.tsx @@ -11,8 +11,6 @@ import { Route as RelationshipRoute } from "@/routes/_app/_authenticated/documen export function DocumentView({ documentId }: { documentId: DocumentId }) { const { docResult } = useDocument(documentId); - console.info(`Rendering document: `, docResult); - if (docResult?.type !== "ready") { return ; } @@ -50,16 +48,14 @@ export function DocumentView({ documentId }: { documentId: DocumentId }) {
    {relationshipList.map((relationshipType) => ( -
    +
    {displayName(relationshipType)} ( {relationshipCounts[relationshipType] ?? 0})
    diff --git a/src/components/documents/RelatedDocumentList.tsx b/src/components/documents/RelatedDocumentList.tsx index a6b23db..514f2ae 100644 --- a/src/components/documents/RelatedDocumentList.tsx +++ b/src/components/documents/RelatedDocumentList.tsx @@ -13,8 +13,6 @@ export function RelatedDocumentList({ documentId, relationshipType }: Props) { const { cache } = useDocumentCache(); - console.log(documentId, docResult, cache); - if (docResult?.type !== "ready") { return ; } diff --git a/src/context/document/DocumentContext.tsx b/src/context/document/DocumentContext.tsx index 5cc94bc..8d459a8 100644 --- a/src/context/document/DocumentContext.tsx +++ b/src/context/document/DocumentContext.tsx @@ -19,6 +19,8 @@ export const DocumentContext = createContext( export function DocumentProvider({ children }: { children: ReactNode }) { const [state, dispatch] = useReducer(reducer, initialState()); + console.log("State: ", state); + return (