summaryrefslogtreecommitdiff
path: root/util/uniorg.tsx
diff options
context:
space:
mode:
authorThomas F. K. Jorna <[email protected]>2021-10-11 21:27:17 +0200
committerGitHub <[email protected]>2021-10-11 21:27:17 +0200
commit58b7030d45370072dee25214748670d6413343a9 (patch)
tree9632df7273415f4b197413c45ad11563af32d53a /util/uniorg.tsx
parent89be3b67b2d10d35d72b5c54e1e166beeeef3095 (diff)
parent6e3dcf585c35620c6804f3c208e6882c29dfc17e (diff)
Merge pull request #101 from org-roam/sidebar
feat: Add file preview functionality
Diffstat (limited to 'util/uniorg.tsx')
-rw-r--r--util/uniorg.tsx61
1 files changed, 61 insertions, 0 deletions
diff --git a/util/uniorg.tsx b/util/uniorg.tsx
new file mode 100644
index 0000000..8802dd1
--- /dev/null
+++ b/util/uniorg.tsx
@@ -0,0 +1,61 @@
+import React, { useEffect, useMemo, useState } from 'react'
+import { OrgRoamNode } from '../api'
+import { NodeByCite, NodeById } from '../pages/index'
+import { ProcessedOrg } from './processOrg'
+
+export interface UniOrgProps {
+ nodeById: NodeById
+ previewNode: any
+ setPreviewNode: any
+ nodeByCite: NodeByCite
+ setSidebarHighlightedNode: any
+ openContextMenu: any
+}
+
+export const UniOrg = (props: UniOrgProps) => {
+ const {
+ openContextMenu,
+ setSidebarHighlightedNode,
+ nodeById,
+ nodeByCite,
+ previewNode,
+ setPreviewNode,
+ } = props
+
+ const [previewText, setPreviewText] = useState('')
+
+ const file = encodeURIComponent(encodeURIComponent(previewNode.file))
+ useEffect(() => {
+ fetch(`http://localhost:35901/file/${file}`)
+ .then((res) => {
+ return res.text()
+ })
+ .then((res) => {
+ if (res !== 'error') {
+ setPreviewText(res)
+ }
+ })
+ .catch((e) => {
+ console.log(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.'
+ })
+ }, [previewNode.id])
+
+ return (
+ <>
+ {previewNode?.id && (
+ <ProcessedOrg
+ {...{
+ nodeById,
+ previewNode,
+ setPreviewNode,
+ previewText,
+ nodeByCite,
+ setSidebarHighlightedNode,
+ openContextMenu,
+ }}
+ />
+ )}
+ </>
+ )
+}