diff options
author | Thomas F. K. Jorna <[email protected]> | 2021-10-11 21:27:17 +0200 |
---|---|---|
committer | GitHub <[email protected]> | 2021-10-11 21:27:17 +0200 |
commit | 58b7030d45370072dee25214748670d6413343a9 (patch) | |
tree | 9632df7273415f4b197413c45ad11563af32d53a /components/Sidebar/Backlinks.tsx | |
parent | 89be3b67b2d10d35d72b5c54e1e166beeeef3095 (diff) | |
parent | 6e3dcf585c35620c6804f3c208e6882c29dfc17e (diff) |
Merge pull request #101 from org-roam/sidebar
feat: Add file preview functionality
Diffstat (limited to 'components/Sidebar/Backlinks.tsx')
-rw-r--r-- | components/Sidebar/Backlinks.tsx | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/components/Sidebar/Backlinks.tsx b/components/Sidebar/Backlinks.tsx new file mode 100644 index 0000000..d82fbba --- /dev/null +++ b/components/Sidebar/Backlinks.tsx @@ -0,0 +1,74 @@ +import { LinksByNodeId, NodeByCite, NodeById } from '../../pages/index' + +import { GraphData, NodeObject, LinkObject } from 'force-graph' + +import { normalizeLinkEnds } from '../../pages/index' +import { VStack, Box, Button, Heading, StackDivider } from '@chakra-ui/react' +import React from 'react' +import { ProcessedOrg } from '../../util/processOrg' + +export interface BacklinksProps { + previewNode: any + setPreviewNode: any + nodeById: NodeById + linksByNodeId: LinksByNodeId + nodeByCite: NodeByCite + setSidebarHighlightedNode: OrgRoamNode + openContextMenu: any +} + +import { PreviewLink } from './Link' +import { OrgRoamNode } from '../../api' + +export const Backlinks = (props: BacklinksProps) => { + const { + previewNode, + setPreviewNode, + setSidebarHighlightedNode, + nodeById, + linksByNodeId, + nodeByCite, + openContextMenu, + } = props + const links = linksByNodeId[previewNode?.id] ?? [] + + const backLinks = links + .filter((link: LinkObject) => { + const [source, target] = normalizeLinkEnds(link) + return source !== previewNode?.id + }) + .map((l) => l.source) + + return ( + <Box> + <Heading pt={4}>{`Backlinks (${backLinks.length})`}</Heading> + <VStack + py={2} + spacing={3} + alignItems="start" + divider={<StackDivider borderColor="gray.500" />} + align="stretch" + color="gray.800" + > + {previewNode?.id && + backLinks.map((link) => { + const title = nodeById[link as string]?.title ?? '' + return ( + <Box overflow="hidden" p={3} bg="gray.300" width="100%" key={link}> + <PreviewLink + nodeByCite={nodeByCite} + setSidebarHighlightedNode={setSidebarHighlightedNode} + href={`id:${link as string}`} + nodeById={nodeById} + setPreviewNode={setPreviewNode} + openContextMenu={openContextMenu} + > + {nodeById[link as string]?.title} + </PreviewLink> + </Box> + ) + })} + </VStack> + </Box> + ) +} |