From 2384b30a244c7d6477e54de5385fe7f1cc62d43a Mon Sep 17 00:00:00 2001 From: "Thomas F. K. Jorna" Date: Fri, 8 Oct 2021 23:39:37 +0200 Subject: feat(preview): proper file preview with api routing --- components/Sidebar/index.tsx | 335 ++++++++----------------------------------- 1 file changed, 56 insertions(+), 279 deletions(-) (limited to 'components/Sidebar/index.tsx') diff --git a/components/Sidebar/index.tsx b/components/Sidebar/index.tsx index e56a25d..4d807ef 100644 --- a/components/Sidebar/index.tsx +++ b/components/Sidebar/index.tsx @@ -1,42 +1,17 @@ import React, { useContext, useEffect, useState } from 'react' -import { UniOrg } from '../../util/uniorg' -import { Backlinks } from './Backlinks' -import { getOrgText } from '../../util/webSocketFunctions' +import { Toolbar } from './Toolbar' +import { Note } from './Note' -import { - Button, - Slide, - VStack, - Flex, - Heading, - Box, - CloseButton, - Text, - Drawer, - DrawerOverlay, - DrawerHeader, - DrawerBody, - DrawerCloseButton, - DrawerContent, - DrawerFooter, - IconButton, -} from '@chakra-ui/react' +import { Button, Slide, VStack, Flex, Heading, Box, 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 { BiFile } 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' +import { LinksByNodeId, NodeByCite, NodeById } from '../../pages/index' export interface SidebarProps { isOpen: boolean @@ -46,68 +21,74 @@ export interface SidebarProps { previewNode: NodeObject setPreviewNode: any linksByNodeId: LinksByNodeId + nodeByCite: NodeByCite + setSidebarHighlightedNode: any } const Sidebar = (props: SidebarProps) => { - const { isOpen, onOpen, onClose, previewNode, setPreviewNode, nodeById, linksByNodeId } = props + const { + isOpen, + onOpen, + onClose, + previewNode, + setPreviewNode, + nodeById, + linksByNodeId, + nodeByCite, + setSidebarHighlightedNode, + } = 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) { + if (!previewNode?.id) { onClose() return } onOpen() setPreviewRoamNode(previewNode as OrgRoamNode) - }, [previewNode.id]) + }, [previewNode?.id]) - const [justification, setJustification] = useState(0) + const [justification, setJustification] = useState(1) 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} - } @@ -116,6 +97,7 @@ const Sidebar = (props: SidebarProps) => { 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', - ) - }} - /> - - - - - - - )} - + /> @@ -355,7 +136,3 @@ const Sidebar = (props: SidebarProps) => { } export default Sidebar - -/* - {previewNode.title} - */ -- cgit v1.2.3