enhance: allow Tag and Property to have notes

pull/10981/head
Tienson Qin 2024-08-08 17:46:53 +08:00
parent d132f41cab
commit d70ef31be5
2 changed files with 69 additions and 46 deletions

View File

@ -175,7 +175,7 @@
(date/journal-title->int (date/today)))) (date/journal-title->int (date/today))))
(state/pub-event! [:journal/insert-template page-name]))) (state/pub-event! [:journal/insert-template page-name])))
state)} state)}
[state _repo page-e {:keys [sidebar? whiteboard?] :as config}] [state repo page-e {:keys [sidebar? whiteboard?] :as config}]
(when page-e (when page-e
(let [page-name (or (:block/name page-e) (let [page-name (or (:block/name page-e)
(str (:block/uuid page-e))) (str (:block/uuid page-e)))
@ -183,33 +183,51 @@
block (get-block (or (:block/uuid page-e) (:block/name page-e))) block (get-block (or (:block/uuid page-e) (:block/name page-e)))
block? (not (db/page? block)) block? (not (db/page? block))
children (:block/_parent block) children (:block/_parent block)
*loading? (:*loading? config) children (cond
loading? (when *loading? (rum/react *loading?))] (ldb/class? block)
(cond (remove (fn [b] (contains? (set (map :db/id (:block/tags b))) (:db/id block))) children)
(and
(not loading?)
(not block?)
(empty? children))
(dummy-block page-e)
:else (ldb/property? block)
(let [document-mode? (state/sub :document/mode?) (remove (fn [b] (some? (get block (:db/ident b)))) children)
hiccup-config (merge
{:id (if block? (str block-id) page-name) :else
:db/id (:db/id block) children)
:block? block? *loading? (:*loading? config)
:editor-box editor/box loading? (when *loading? (rum/react *loading?))
:document/mode? document-mode?} db-based? (config/db-based-graph? repo)]
config) [:<>
config (common-handler/config-with-document-mode hiccup-config) (when (and db-based? (or (ldb/class? block) (ldb/property? block)))
blocks (if block? [block] (db/sort-by-order children block))] [:div.font-medium.mt-8.ml-1.opacity-50
[:div "Notes"])
(page-blocks-inner page-e blocks config sidebar? whiteboard? block-id)
(when-not config/publishing? (cond
(let [args (if block-id loading?
{:block-uuid block-id} nil
{:page page-name})]
(add-button args)))]))))) (and
(not loading?)
(not block?)
(empty? children))
(dummy-block page-e)
:else
(let [document-mode? (state/sub :document/mode?)
hiccup-config (merge
{:id (if block? (str block-id) page-name)
:db/id (:db/id block)
:block? block?
:editor-box editor/box
:document/mode? document-mode?}
config)
config (common-handler/config-with-document-mode hiccup-config)
blocks (if block? [block] (db/sort-by-order children block))]
[:div
(page-blocks-inner page-e blocks config sidebar? whiteboard? block-id)
(when-not config/publishing?
(let [args (if block-id
{:block-uuid block-id}
{:page page-name})]
(add-button args)))]))])))
(rum/defc today-queries < rum/reactive (rum/defc today-queries < rum/reactive
[repo today? sidebar?] [repo today? sidebar?]
@ -572,17 +590,14 @@
[:div.mt-8 [:div.mt-8
(objects/property-related-objects page)]) (objects/property-related-objects page)])
(when-not (and db-based? (or (ldb/class? page) (ldb/property? page))) (when (and block? (not sidebar?) (not whiteboard?))
[:div (let [config (merge config {:id "block-parent"
(when (and block? (not sidebar?) (not whiteboard?)) :block? true})]
(let [config (merge config {:id "block-parent" [:div.mb-4
:block? true})] (component-block/breadcrumb config repo block-id {:level-limit 3})]))
[:div.mb-4
(component-block/breadcrumb config repo block-id {:level-limit 3})]))
;; blocks (page-blocks-cp repo page (merge option {:sidebar? sidebar?
(page-blocks-cp repo page (merge option {:sidebar? sidebar? :whiteboard? whiteboard?}))])
:whiteboard? whiteboard?}))])])
(when (and (not preview?) @(::main-ready? state)) (when (and (not preview?) @(::main-ready? state))
[:div {:style {:padding-left 9}} [:div {:style {:padding-left 9}}

View File

@ -319,7 +319,9 @@
(let [tx-data [[:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)] (let [tx-data [[:db/add [:block/uuid block-id] :block/tags (:db/id tag-entity)]
;; TODO: Move this to outliner.core to consistently add refs for tags ;; TODO: Move this to outliner.core to consistently add refs for tags
[:db/add [:block/uuid block-id] :block/refs (:db/id tag-entity)]]] [:db/add [:block/uuid block-id] :block/refs (:db/id tag-entity)]]]
(db/transact! repo tx-data {:outliner-op :save-block}))) (ui-outliner-tx/transact! {:outliner-op :save-block}
(editor-handler/save-current-block!)
(db/transact! repo tx-data {:outliner-op :save-block}))))
(defn on-chosen-handler (defn on-chosen-handler
[input id _q pos format] [input id _q pos format]
@ -338,7 +340,10 @@
(fn [chosen-result e] (fn [chosen-result e]
(util/stop e) (util/stop e)
(state/clear-editor-action!) (state/clear-editor-action!)
(let [chosen (:block/title chosen-result) (let [chosen-result (if (:block/uuid chosen-result)
(db/entity [:block/uuid (:block/uuid chosen-result)])
chosen-result)
chosen (:block/title chosen-result)
class? (and db-based? hashtag? class? (and db-based? hashtag?
(or (string/includes? chosen (str (t :new-tag) " ")) (or (string/includes? chosen (str (t :new-tag) " "))
(ldb/class? (db/get-page chosen)))) (ldb/class? (db/get-page chosen))))
@ -357,6 +362,12 @@
q)) q))
last-pattern (str "#" (when wrapped? page-ref/left-brackets) last-pattern)] last-pattern (str "#" (when wrapped? page-ref/left-brackets) last-pattern)]
(p/do! (p/do!
(editor-handler/insert-command! id
(if class? "" (str "#" wrapped-tag))
format
{:last-pattern last-pattern
:end-pattern (when wrapped? page-ref/right-brackets)
:command :page-ref})
(when db-based? (when db-based?
(let [tag (string/trim chosen) (let [tag (string/trim chosen)
edit-block (state/get-edit-block)] edit-block (state/get-edit-block)]
@ -370,18 +381,15 @@
(when class? (when class?
(let [tag-entity (or (when (de/entity? chosen-result) chosen-result) result)] (let [tag-entity (or (when (de/entity? chosen-result) chosen-result) result)]
(add-tag (state/get-current-repo) (:block/uuid edit-block) tag-entity))))))) (add-tag (state/get-current-repo) (:block/uuid edit-block) tag-entity)))))))
(editor-handler/insert-command! id
(if class? "" (str "#" wrapped-tag))
format
{:last-pattern last-pattern
:end-pattern (when wrapped? page-ref/right-brackets)
:command :page-ref})
(when input (.focus input))))) (when input (.focus input)))))
(fn [chosen-result e] (fn [chosen-result e]
(util/stop e) (util/stop e)
(state/clear-editor-action!) (state/clear-editor-action!)
(let [chosen (:block/title chosen-result) (let [chosen-result (if (:block/uuid chosen-result)
(db/entity [:block/uuid (:block/uuid chosen-result)])
chosen-result)
chosen (:block/title chosen-result)
chosen' (string/replace-first chosen (str (t :new-page) " ") "") chosen' (string/replace-first chosen (str (t :new-page) " ") "")
ref-text (if (and (de/entity? chosen-result) (not (ldb/page? chosen-result))) ref-text (if (and (de/entity? chosen-result) (not (ldb/page? chosen-result)))
(cond (cond