From b0ddf286f087b31dc75626f709cfce3889de25dd Mon Sep 17 00:00:00 2001
From: "Thomas F. K. Jorna" <hello@tefkah.com>
Date: Mon, 4 Oct 2021 15:34:56 +0200
Subject: feat(preview): changed text-retrieval to http

---
 components/Sidebar/index.tsx | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

(limited to 'components/Sidebar/index.tsx')

diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx
index e3845d9..05f5720 100644
--- a/components/Sidebar/index.tsx
+++ b/components/Sidebar/index.tsx
@@ -33,14 +33,25 @@ export interface SidebarProps {
   onClose: any
   //nodeById: any
   previewNode: NodeObject
-  orgText: string
 }
 
 const Sidebar = (props: SidebarProps) => {
-  const { isOpen, onClose, previewNode, orgText } = props
+  const { isOpen, onClose, previewNode } = props
 
   const { highlightColor } = useContext(ThemeContext)
   const [previewRoamNode, setPreviewRoamNode] = useState<OrgRoamNode>()
+  const [previewText, setPreviewText] = useState('')
+
+  const getText = (id: string) => {
+    fetch(`http://localhost:35901/note/${id}`)
+      .then((res) => {
+        return res.text()
+      })
+      .then((res) => {
+        console.log(res)
+        setPreviewText(res)
+      })
+  }
 
   useEffect(() => {
     if (!previewNode) {
@@ -48,6 +59,7 @@ const Sidebar = (props: SidebarProps) => {
     }
 
     setPreviewRoamNode(previewNode as OrgRoamNode)
+    previewNode?.id && getText(previewNode?.id as string)
   }, [previewNode])
 
   //maybe want to close it when clicking outside, but not sure
@@ -246,7 +258,7 @@ const Sidebar = (props: SidebarProps) => {
                   '.figure p': { textAlign: 'center' },
                 }}
               >
-                <UniOrg orgText={orgText} />
+                <UniOrg orgText={previewText} />
               </Box>
             </VStack>
           </Scrollbars>
-- 
cgit v1.2.3

