fix: property key blinks when adding new property

This commit is contained in:
Tienson Qin
2024-01-26 12:30:54 +08:00
parent 1b7bc6d053
commit 07bdb2e849
2 changed files with 12 additions and 12 deletions

View File

@@ -329,8 +329,7 @@
(defn- add-property-from-dropdown
"Adds an existing or new property from dropdown. Used from a block or page context.
For pages, used to add both schema properties or properties for a page"
[entity property-name {:keys [class-schema? page-configure?
*show-new-property-config?]}]
[entity property-name {:keys [class-schema? page-configure?]}]
(let [repo (state/get-current-repo)]
;; existing property selected or entered
(if-let [_property (get-property-from-db property-name)]
@@ -347,10 +346,9 @@
(if (db-property/valid-property-name? property-name)
(if (and (contains? (:block/type entity) "class") page-configure?)
(pv/<add-property! entity property-name "" {:class-schema? class-schema? :exit-edit? page-configure?})
(do
(p/do!
(db-property-handler/upsert-property! repo property-name {} {})
(when *show-new-property-config?
(reset! *show-new-property-config? true))))
true))
(do (notification/show! "This is an invalid property name. A property name cannot start with page reference characters '#' or '[['." :error)
(pv/exit-edit-property))))))
@@ -375,7 +373,7 @@
:on-chosen on-chosen
:input-opts input-opts})]]))
(rum/defcs property-input < rum/reactive
(rum/defcs property-input < rum/static
(rum/local false ::show-new-property-config?)
shortcut/disable-all-shortcuts
[state entity *property-key *property-value {:keys [class-schema? _page-configure? in-block-container?]
@@ -424,9 +422,12 @@
(pv/property-value entity property @*property-value (assoc opts :editing? true))))]])
(let [on-chosen (fn [{:keys [value]}]
(reset! *property-key value)
(add-property-from-dropdown entity value (assoc opts :*show-new-property-config? *show-new-property-config?)))
input-opts {:on-blur (fn [] (pv/exit-edit-property))
(p/let [result (add-property-from-dropdown entity value opts)]
(reset! *property-key value)
(when (and (true? result) *show-new-property-config?)
(reset! *show-new-property-config? true))))
input-opts {:on-blur (fn []
(pv/exit-edit-property))
:on-key-down
(fn [e]
(case (util/ekey e)

View File

@@ -99,13 +99,12 @@
(let [property (db/entity [:block/name (common-util/page-name-sanity-lc k-name)])
k-name (name k-name)
property-uuid (or (:block/uuid property) property-uuid (db/new-block-id))]
(when property
(if property
(db/transact! repo [(outliner-core/block-with-updated-at
{:block/schema schema
:block/uuid property-uuid
:block/type "property"})]
{:outliner-op :save-block}))
(when (nil? property) ;if property not exists yet
{:outliner-op :save-block})
(db/transact! repo [(sqlite-util/build-new-property
(cond-> {:block/original-name k-name
:block/name (util/page-name-sanity-lc k-name)