import React, { useContext, useEffect, useState } from 'react' import { UniOrg } from '../../util/uniorg' import { Backlinks } from './Backlinks' 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, HamburgerIcon } from '@chakra-ui/icons' import { BiFont, BiAlignJustify, BiAlignLeft, BiAlignMiddle, BiAlignRight, BiRightIndent, } from 'react-icons/bi' import { GraphData, NodeObject, LinkObject } from 'force-graph' import { OrgRoamNode } from '../../api' import { ThemeContext } from '../../util/themecontext' import { LinksByNodeId, NodeById } from '../../pages/index' export interface SidebarProps { isOpen: boolean onClose: any onOpen: any nodeById: NodeById previewNode: NodeObject setPreviewNode: any linksByNodeId: LinksByNodeId } const Sidebar = (props: SidebarProps) => { const { isOpen, onOpen, onClose, previewNode, setPreviewNode, nodeById, linksByNodeId } = props const { highlightColor } = useContext(ThemeContext) const [previewRoamNode, setPreviewRoamNode] = useState() const getText = (id: string, setText: any) => { fetch(`http://localhost:35901/note/${id}`) .then((res) => { return res.text() }) .then((res) => setText(res)) .catch((e) => { return ( 'Could not fetch the text for some reason, sorry!\n\n This can happen because you have an id with forward slashes (/) in it.', console.log(e) ) }) } useEffect(() => { if (!previewNode.id) { onClose() return } onOpen() setPreviewRoamNode(previewNode as OrgRoamNode) }, [previewNode.id]) const [justification, setJustification] = useState(0) const justificationList = ['justify', 'start', 'end', 'center'] const [font, setFont] = useState('sans serif') const [indent, setIndent] = useState(0) //maybe want to close it when clicking outside, but not sure //const outsideClickRef = useRef(); return ( } aria-label="Previous node" /> {previewRoamNode?.title} } aria-label="Close file-viewer" variant="link" onClick={onClose} /> ( )} > {previewNode?.id && ( , , , , ][justification] } onClick={() => setJustification((curr) => (curr + 1) % 4)} /> } onClick={() => { console.log(indent) setIndent((curr: number) => (indent ? 0 : 1)) }} /> } onClick={() => { setFont((curr: string) => curr === 'sans serif' ? 'serif' : 'sans serif', ) }} /> )} ) } export default Sidebar /* {previewNode.title} */