import React, { useContext, useEffect, useState } from 'react' import { UniOrg } from '../../util/uniorg' import { getOrgText } from '../../util/webSocketFunctions' import { Button, Slide, VStack, Flex, Heading, Box, CloseButton, Text, Drawer, DrawerOverlay, DrawerHeader, DrawerBody, DrawerCloseButton, DrawerContent, DrawerFooter, IconButton, } from '@chakra-ui/react' import { Scrollbars } from 'react-custom-scrollbars-2' import { ChevronLeftIcon, ChevronRightIcon } from '@chakra-ui/icons' import { GraphData, NodeObject, LinkObject } from 'force-graph' import { OrgRoamNode } from '../../api' import { ThemeContext } from '../../util/themecontext' export interface SidebarProps { isOpen: boolean onClose: any //nodeById: any previewNode: NodeObject } const Sidebar = (props: SidebarProps) => { const { isOpen, onClose, previewNode } = props const { highlightColor } = useContext(ThemeContext) const [previewRoamNode, setPreviewRoamNode] = useState() 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) }) .catch((e) => { setPreviewText( 'Could not fetch the text for some reason, sorry!\n\n This can happen because you have an id with forward slashes (/) in it.', ) }) } useEffect(() => { if (!previewNode) { return } setPreviewRoamNode(previewNode as OrgRoamNode) previewNode?.id && getText(previewNode?.id as string) }, [previewNode]) //maybe want to close it when clicking outside, but not sure //const outsideClickRef = useRef(); return ( } colorScheme="white" aria-label="Close file-viewer" height={100} variant="ghost" marginRight={-2} bg="alt.100" onClick={onClose} marginTop={20} /> {previewRoamNode?.title} ( )} > ) } export default Sidebar /* {previewNode.title} */