fix: don't render embed page when the current container is the same page

pull/759/head
Tienson Qin 2020-11-25 17:47:23 +08:00
parent 4303ea4ed9
commit 320ac8ad55
4 changed files with 25 additions and 26 deletions

View File

@ -321,19 +321,20 @@
[config page-name]
(let [page-name (string/lower-case page-name)
page-original-name (:page/original-name (db/entity [:page/name page-name]))
blocks (db/get-page-blocks (state/get-current-repo) page-name)
current-page (state/get-current-page)]
[:div.embed-page.py-2.my-2.px-3.bg-base-2
[:p
[:code.mr-2 "Embed page:"]
(page-cp config {:page/name page-name})]
(when (or
(not current-page)
(and current-page
(not= (string/lower-case current-page) page-name)))
(blocks-container blocks (assoc config
:embed? true
:ref? false)))]))
(when (and
(not= (string/lower-case (or current-page ""))
page-name)
(not= (string/lower-case (get config :id ""))
page-name))
(let [blocks (db/get-page-blocks (state/get-current-repo) page-name)]
(blocks-container blocks (assoc config
:embed? true
:ref? false))))]))
(defn- get-label-text
[label]

View File

@ -21,7 +21,7 @@
(rum/defc blocks-inner < rum/static
{:did-mount (fn [state]
(let [[blocks _ page] (:rum/args state)
(let [[blocks page] (:rum/args state)
first-title (second (first (:block/title (first blocks))))
journal? (and (string? first-title)
(date/valid-journal-title? first-title))]
@ -39,25 +39,25 @@
:error
false)))
state)}
[blocks encoded-page-name page document-mode?]
[blocks page document-mode?]
(let [start-level (or (:block/level (first blocks)) 1)
config {:id encoded-page-name
config {:id page
:start-level 2
:editor-box editor/box
:document/mode? document-mode?}]
(content/content
encoded-page-name
page
{:hiccup (block/->hiccup blocks config {})})))
(rum/defc blocks-cp < rum/reactive db-mixins/query
{}
[repo page encoded-page-name format]
[repo page format]
(let [raw-blocks (db/get-page-blocks repo page)
document-mode? (state/sub :document/mode?)
blocks (->>
(db/with-dummy-block raw-blocks format nil {:journal? true})
(db/with-block-refs-count repo))]
(blocks-inner blocks encoded-page-name page document-mode?)))
(blocks-inner blocks page document-mode?)))
(rum/defc journal-cp < rum/reactive
[[title format]]
@ -86,7 +86,7 @@
[:h1.title
(util/capitalize-all title)]]
(blocks-cp repo page encoded-page-name format))
(blocks-cp repo page format))
(page/today-queries repo today? false)

View File

@ -66,7 +66,7 @@
{:journal? journal?
:page-name page-name})
start-level (or (:block/level (first page-blocks)) 1)
hiccup-config {:id encoded-page-name
hiccup-config {:id page-name
:start-level start-level
:sidebar? sidebar?
:block? block?
@ -74,7 +74,7 @@
hiccup-config (common-handler/config-with-document-mode hiccup-config)
hiccup (block/->hiccup page-blocks hiccup-config {})]
(rum/with-key
(content/content encoded-page-name
(content/content page-name
{:hiccup hiccup
:sidebar? sidebar?})
(str encoded-page-name "-hiccup"))))

View File

@ -18,7 +18,6 @@
(let [block? (util/uuid-string? page-name)
block-id (and block? (uuid page-name))
page-name (string/lower-case page-name)
encoded-page-name (util/url-encode page-name)
journal? (date/valid-journal-title? (string/capitalize page-name))
ref-blocks (cond
priority?
@ -44,13 +43,13 @@
"SCHEDULED AND DEADLINE")]
[:div.references-blocks.mb-6
(let [ref-hiccup (block/->hiccup scheduled-or-deadlines
{:id (str encoded-page-name "-agenda")
{:id (str page-name "-agenda")
:start-level 2
:ref? true
:group-by-page? true
:editor-box editor/box}
{})]
(content/content encoded-page-name
(content/content page-name
{:hiccup ref-hiccup}))]))
(ui/foldable
@ -58,30 +57,29 @@
(str n-ref " Linked References"))]
[:div.references-blocks
(let [ref-hiccup (block/->hiccup ref-blocks
{:id encoded-page-name
{:id page-name
:start-level 2
:ref? true
:breadcrumb-show? true
:group-by-page? true
:editor-box editor/box}
{})]
(content/content encoded-page-name
(content/content page-name
{:hiccup ref-hiccup}))])]]))))
(rum/defc unlinked-references-aux < rum/reactive db-mixins/query
[page-name n-ref]
(let [ref-blocks (db/get-page-unlinked-references page-name)
encoded-page-name (util/url-encode page-name)]
(let [ref-blocks (db/get-page-unlinked-references page-name)]
(reset! n-ref (count ref-blocks))
[:div.references-blocks
(let [ref-hiccup (block/->hiccup ref-blocks
{:id (str encoded-page-name "-unlinked-")
{:id (str page-name "-unlinked-")
:start-level 2
:ref? true
:group-by-page? true
:editor-box editor/box}
{})]
(content/content encoded-page-name
(content/content page-name
{:hiccup ref-hiccup}))]))
(rum/defcs unlinked-references < rum/reactive