From ec13cff2be45360d358cb6c789a85db3fef37e74 Mon Sep 17 00:00:00 2001 From: Trang Doan Date: Fri, 28 Nov 2025 15:05:19 -0500 Subject: [PATCH] finished --- .../src/components/RelationshipSection.tsx | 83 ++++++++++++++++++- turbo.json | 4 +- 2 files changed, 81 insertions(+), 6 deletions(-) diff --git a/apps/obsidian/src/components/RelationshipSection.tsx b/apps/obsidian/src/components/RelationshipSection.tsx index 6034a2a36..731791594 100644 --- a/apps/obsidian/src/components/RelationshipSection.tsx +++ b/apps/obsidian/src/components/RelationshipSection.tsx @@ -356,7 +356,7 @@ const CurrentRelationships = ({ activeFile }: RelationshipSectionProps) => { }; }, [activeFile, plugin]); - const loadCurrentRelationships = async () => { + const loadCurrentRelationships = useCallback(async () => { const fileCache = plugin.app.metadataCache.getFileCache(activeFile); if (!fileCache?.frontmatter) return; @@ -423,7 +423,72 @@ const CurrentRelationships = ({ activeFile }: RelationshipSectionProps) => { } setGroupedRelationships(Array.from(tempRelationships.values())); - }; + }, [activeFile, plugin]); + + const deleteRelationship = useCallback( + async (linkedFile: TFile, relationTypeId: string) => { + const relationType = plugin.settings.relationTypes.find( + (r) => r.id === relationTypeId, + ); + if (!relationType) return; + + try { + const removeLinkFromFrontmatter = async ( + file: TFile, + targetFileName: string, + relationTypeId: string, + ) => { + await plugin.app.fileManager.processFrontMatter(file, (fm) => { + const existingLinks = Array.isArray(fm[relationTypeId]) + ? fm[relationTypeId] + : [fm[relationTypeId]].filter(Boolean); + + const linkToRemove = `[[${targetFileName}]]`; + const filteredLinks = existingLinks.filter( + (link) => link !== linkToRemove, + ); + + if (filteredLinks.length === 0) { + delete fm[relationTypeId]; + } else { + fm[relationTypeId] = filteredLinks; + } + }); + }; + + // Remove link from active file + await removeLinkFromFrontmatter( + activeFile, + linkedFile.name, + relationTypeId, + ); + + // Remove reverse link from linked file + await removeLinkFromFrontmatter( + linkedFile, + activeFile.name, + relationTypeId, + ); + + new Notice( + `Successfully removed ${relationType.label} with ${linkedFile.basename}`, + ); + + loadCurrentRelationships(); + } catch (error) { + console.error("Failed to delete relationship:", error); + new Notice( + `Failed to delete relationship: ${error instanceof Error ? error.message : "Unknown error"}`, + ); + } + }, + [ + activeFile, + plugin.app.fileManager, + plugin.settings.relationTypes, + loadCurrentRelationships, + ], + ); if (groupedRelationships.length === 0) return null; @@ -445,10 +510,10 @@ const CurrentRelationships = ({ activeFile }: RelationshipSectionProps) => { diff --git a/turbo.json b/turbo.json index 18ab2bcde..7df925c17 100644 --- a/turbo.json +++ b/turbo.json @@ -61,10 +61,10 @@ "inputs": ["$TURBO_DEFAULT$", ".env*"] }, "roam#dev": { - "with": ["@repo/database#dev"] + "dependsOn": ["@repo/database#dev"] }, "website#dev": { - "with": ["@repo/database#dev"] + "dependsOn": ["@repo/database#dev"] }, "genenv": { "env": ["SUPABASE_USE_DB"],