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/Backlinks.tsx | 44 +++++++++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 14 deletions(-) (limited to 'components/Sidebar/Backlinks.tsx') diff --git a/components/Sidebar/Backlinks.tsx b/components/Sidebar/Backlinks.tsx index f899d3e..8c1e9bc 100644 --- a/components/Sidebar/Backlinks.tsx +++ b/components/Sidebar/Backlinks.tsx @@ -1,4 +1,4 @@ -import { LinksByNodeId, NodeById } from '../../pages/index' +import { LinksByNodeId, NodeByCite, NodeById } from '../../pages/index' import { GraphData, NodeObject, LinkObject } from 'force-graph' @@ -12,17 +12,34 @@ export interface BacklinksProps { setPreviewNode: any nodeById: NodeById linksByNodeId: LinksByNodeId - getText: any + nodeByCite: NodeByCite + setSidebarHighlightedNode: OrgRoamNode } import { PreviewLink } from './Link' +import { OrgRoamNode } from '../../api' export const Backlinks = (props: BacklinksProps) => { - const { previewNode, setPreviewNode, nodeById, linksByNodeId, getText } = props + const { + previewNode, + setPreviewNode, + setSidebarHighlightedNode, + nodeById, + linksByNodeId, + nodeByCite, + } = 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 ( - {'Backlinks (' + links.length + ')'} + {`Backlinks (${backLinks.length})`} { color="gray.800" > {previewNode?.id && - links.map((link: LinkObject, i: number) => { - const [source, target] = normalizeLinkEnds(link) - if (source === previewNode?.id) { - return - } + backLinks.map((link) => { + const title = nodeById[link as string]?.title ?? '' return ( - + + > + {nodeById[link as string]?.title} + ) })} -- cgit v1.2.3