Sfoglia il codice sorgente

fix: can't edit notes for class and property page

Tienson Qin 1 anno fa
parent
commit
59103a1607

+ 6 - 4
src/main/frontend/components/page.cljs

@@ -115,10 +115,12 @@
     (when page
       (let [[hover set-hover!] (rum/use-state false)
             click-handler-fn (fn []
-                               (p/do!
-                                (editor-handler/insert-first-page-block-if-not-exists! (:block/uuid page))
-                                (when-let [first-child (first (:block/_page (db/entity (:db/id page))))]
-                                  (editor-handler/edit-block! first-child :max {:container-id :unknown-container}))))
+                               (p/let [result (editor-handler/insert-first-page-block-if-not-exists! (:block/uuid page))
+                                       result (when (string? result) (:tx-data (ldb/read-transit-str result)))
+                                       first-child-id (first (map :block/uuid result))
+                                       first-child (when first-child-id (db/entity [:block/uuid first-child-id]))]
+                                 (when first-child
+                                   (editor-handler/edit-block! first-child :max {:container-id :unknown-container}))))
             drop-handler-fn (fn [^js event]
                               (util/stop event)
                               (p/let [block-uuids (state/get-selection-block-ids)

+ 8 - 7
src/main/frontend/handler/editor.cljs

@@ -604,13 +604,14 @@
   (let [page-title (str page-uuid-or-title)]
     (when-not (string/blank? page-title)
       (when-let [page (db/get-page page-title)]
-        (when (db/page-empty? (state/get-current-repo) (:db/id page))
-          (let [format (or (:block/format page) (state/get-preferred-format))
-                new-block {:block/title ""
-                           :block/format format}]
-            (ui-outliner-tx/transact!
-             {:outliner-op :insert-blocks}
-             (outliner-op/insert-blocks! [new-block] page {:sibling? false}))))))))
+        (let [class-or-property? (or (ldb/class? page) (ldb/property? page))]
+          (when (or class-or-property? (db/page-empty? (state/get-current-repo) (:db/id page)))
+           (let [format (or (:block/format page) (state/get-preferred-format))
+                 new-block {:block/title ""
+                            :block/format format}]
+             (ui-outliner-tx/transact!
+              {:outliner-op :insert-blocks}
+              (outliner-op/insert-blocks! [new-block] page {:sibling? false})))))))))
 
 (defn update-timestamps-content!
   [{:block/keys [repeated? marker format] :as block} content]