From 11298a51b44b6bc17c34522deac5f5ac370340a0 Mon Sep 17 00:00:00 2001
From: "Thomas F. K. Jorna" <thomasfkjorna@gmail.com>
Date: Sun, 1 Aug 2021 16:28:34 +0200
Subject: fixed filtering for dirty links

---
 pages/index.tsx | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

(limited to 'pages/index.tsx')

diff --git a/pages/index.tsx b/pages/index.tsx
index afb4bad..82c203c 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -107,7 +107,13 @@ export function GraphPage() {
 
     nodeByIdRef.current = Object.fromEntries(orgRoamGraphData.nodes.map((node) => [node.id, node]))
 
-    const links = [...orgRoamGraphData.links, ...fileLinks]
+    const dirtyLinks = [...orgRoamGraphData.links, ...fileLinks]
+    const links = dirtyLinks.filter((link) => {
+      const sourceId = link.source as string
+      const targetId = link.target as string
+      return nodeByIdRef.current[sourceId] && nodeByIdRef.current[targetId]
+    })
+
     linksByNodeIdRef.current = links.reduce<LinksByNodeId>((acc, link) => {
       return {
         ...acc,
@@ -410,12 +416,7 @@ export const Graph = forwardRef(function (props: GraphProps, graphRef: any) {
     const filteredNodeIds = filteredNodes.map((node) => node.id as string)
     const filteredLinks = graphData.links.filter((linkArg) => {
       const link = linkArg as OrgRoamLink
-      return (
-        link.type !== 'cite' &&
-        (filter.parents || link.type !== 'parent') &&
-        filteredNodeIds.includes(link.source as string) &&
-        filteredNodeIds.includes(link.target)
-      )
+      return link.type !== 'cite' && (filter.parents || link.type !== 'parent')
     })
 
     const scopedNodes = filteredNodes.filter((node) => {
-- 
cgit v1.2.3

