From a21b4afd4f54a53e5d563c3d02195e05f48a4700 Mon Sep 17 00:00:00 2001
From: "Thomas F. K. Jorna" <thomasfkjorna@gmail.com>
Date: Sun, 12 Sep 2021 19:38:51 +0200
Subject: fix: #81 Ui now loads on empty db

---
 pages/index.tsx | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

(limited to 'pages/index.tsx')

diff --git a/pages/index.tsx b/pages/index.tsx
index 421ead4..d4235d7 100644
--- a/pages/index.tsx
+++ b/pages/index.tsx
@@ -95,7 +95,9 @@ export function GraphPage() {
   const updateGraphData = (orgRoamGraphData: OrgRoamGraphReponse) => {
     const oldNodeById = nodeByIdRef.current
     tagsRef.current = orgRoamGraphData.tags ?? []
-    const nodesByFile = orgRoamGraphData.nodes.reduce<NodesByFile>((acc, node) => {
+    const importNodes = orgRoamGraphData.nodes ?? []
+    const importLinks = orgRoamGraphData.links ?? []
+    const nodesByFile = importNodes.reduce<NodesByFile>((acc, node) => {
       return {
         ...acc,
         [node.file]: [...(acc[node.file] ?? []), node],
@@ -161,8 +163,8 @@ export function GraphPage() {
       })
     })
 
-    nodeByIdRef.current = Object.fromEntries(orgRoamGraphData.nodes.map((node) => [node.id, node]))
-    const dirtyLinks = [...orgRoamGraphData.links, ...headingLinks, ...fileLinks]
+    nodeByIdRef.current = Object.fromEntries(importNodes.map((node) => [node.id, node]))
+    const dirtyLinks = [...importLinks, ...headingLinks, ...fileLinks]
     const nonExistantNodes: OrgRoamNode[] = []
     const links = dirtyLinks.map((link) => {
       const sourceId = link.source as string
@@ -209,7 +211,7 @@ export function GraphPage() {
       }
     }, {})
 
-    const nodes = [...orgRoamGraphData.nodes, ...nonExistantNodes]
+    const nodes = [...importNodes, ...nonExistantNodes]
     const orgRoamGraphDataProcessed = {
       nodes,
       links,
-- 
cgit v1.2.3

