Skip to content

Commit

Permalink
fix: do not show links for the current page
Browse files Browse the repository at this point in the history
  • Loading branch information
pengx17 authored and tiensonqin committed Dec 6, 2022
1 parent e74d9d3 commit 9dff0db
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/frontend/extensions/tldraw.cljs
Expand Up @@ -78,6 +78,7 @@
(defn get-tldraw-handlers [current-whiteboard-name]
{:search search-handler
:queryBlockByUUID #(clj->js (model/query-block-by-uuid (parse-uuid %)))
:getBlockPageName #(:block/name (model/get-block-page (state/get-current-repo) (parse-uuid %)))
:isWhiteboardPage model/whiteboard-page?
:saveAsset save-asset-handler
:makeAssetUrl editor-handler/make-asset-url
Expand Down
2 changes: 1 addition & 1 deletion src/main/frontend/handler/whiteboard.cljs
Expand Up @@ -96,7 +96,7 @@
:selectedIds #js[]
:pages [(merge tldr-page
{:id id
:name "page"
:name (:block/name page-block)
:shapes shapes})]})))

(defn transact-tldr! [page-name tldr]
Expand Down
Expand Up @@ -12,7 +12,7 @@ export const BlockLink = ({
}) => {
const {
handlers: { isWhiteboardPage, redirectToPage, sidebarAddBlock, queryBlockByUUID },
renderers: { Breadcrumb, PageName, BlockReference },
renderers: { Breadcrumb, PageName },
} = React.useContext(LogseqContext)

let iconName = ''
Expand Down
12 changes: 10 additions & 2 deletions tldraw/apps/tldraw-logseq/src/components/QuickLinks/QuickLinks.tsx
@@ -1,10 +1,13 @@
import type { TLQuickLinksComponent } from '@tldraw/react'
import { TLQuickLinksComponent, useApp } from '@tldraw/react'
import { observer } from 'mobx-react-lite'
import React from 'react'
import type { Shape } from '../../lib'
import { LogseqContext } from '../../lib/logseq-context'
import { BlockLink } from '../BlockLink'

export const QuickLinks: TLQuickLinksComponent<Shape> = observer(({ shape }) => {
const app = useApp()
const { handlers } = React.useContext(LogseqContext)
const links = React.useMemo(() => {
const links = [...(shape.props.refs ?? [])].map<[ref: string, showReferenceContent: boolean]>(
// user added links should show the referenced block content
Expand All @@ -16,7 +19,12 @@ export const QuickLinks: TLQuickLinksComponent<Shape> = observer(({ shape }) =>
links.unshift([shape.props.pageId, false])
}

return links
// do not show links for the current page
return links.filter(
link =>
link[0].toLowerCase() !== app.currentPage.name &&
handlers.getBlockPageName(link[0]) !== app.currentPage.name
)
}, [shape.props.type, shape.props.parentId, shape.props.refs])

if (links.length === 0) return null
Expand Down
1 change: 1 addition & 0 deletions tldraw/apps/tldraw-logseq/src/lib/logseq-context.ts
Expand Up @@ -43,6 +43,7 @@ export interface LogseqContextValue {
addNewWhiteboard: (pageName: string) => void
addNewBlock: (content: string) => string // returns the new block uuid
queryBlockByUUID: (uuid: string) => any
getBlockPageName: (uuid: string) => string
isWhiteboardPage: (pageName: string) => boolean
saveAsset: (file: File) => Promise<string>
makeAssetUrl: (relativeUrl: string) => string
Expand Down

0 comments on commit 9dff0db

Please sign in to comment.