QuickLinks.tsx 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import { TLQuickLinksComponent, useApp } from '@tldraw/react'
  2. import { observer } from 'mobx-react-lite'
  3. import React from 'react'
  4. import type { Shape } from '../../lib'
  5. import { LogseqContext } from '../../lib/logseq-context'
  6. import { BlockLink } from '../BlockLink'
  7. export const QuickLinks: TLQuickLinksComponent<Shape> = observer(({ shape }) => {
  8. const app = useApp()
  9. const { handlers } = React.useContext(LogseqContext)
  10. const links = React.useMemo(() => {
  11. const links = [...(shape.props.refs ?? [])].map<[ref: string, showReferenceContent: boolean]>(
  12. // user added links should show the referenced block content
  13. l => [l, true]
  14. )
  15. if (shape.props.type === 'logseq-portal' && shape.props.pageId) {
  16. // portal reference should not show the block content
  17. links.unshift([shape.props.pageId, false])
  18. }
  19. // do not show links for the current page
  20. return links.filter(
  21. link =>
  22. link[0].toLowerCase() !== app.currentPage.name &&
  23. handlers.getBlockPageName(link[0]) !== app.currentPage.name
  24. )
  25. }, [shape.props.type, shape.props.parentId, shape.props.refs])
  26. if (links.length === 0) return null
  27. return (
  28. <div className="tl-quick-links" title="Shape Quick Links">
  29. {links.map(([ref, showReferenceContent]) => {
  30. return (
  31. <div key={ref} className="tl-quick-links-row">
  32. <BlockLink id={ref} showReferenceContent={showReferenceContent} />
  33. </div>
  34. )
  35. })}
  36. </div>
  37. )
  38. })