mirror of
https://github.com/logseq/logseq.git
synced 2026-04-24 14:14:55 +00:00
enhance(ux): don't clear input after adding a page to Library
fixes https://github.com/logseq/db-test/issues/352
This commit is contained in:
@@ -55,7 +55,8 @@
|
||||
:input-default-placeholder "Add pages"
|
||||
:show-new-when-not-exact-match? false
|
||||
:on-input set-input!
|
||||
:input-opts {:class "!p-1 !text-sm"}})))
|
||||
:input-opts {:class "!p-1 !text-sm"}
|
||||
:clear-input-on-chosen? false})))
|
||||
|
||||
(rum/defc add-pages
|
||||
[library-page]
|
||||
|
||||
@@ -107,7 +107,8 @@
|
||||
item-cp transform-fn tap-*input-val
|
||||
multiple-choices? on-apply new-case-sensitive?
|
||||
dropdown? show-new-when-not-exact-match? exact-match-exclude-items
|
||||
input-container initial-open? loading?]
|
||||
input-container initial-open? loading?
|
||||
clear-input-on-chosen?]
|
||||
:or {limit 100
|
||||
prompt-key :select/default-prompt
|
||||
empty-placeholder (fn [_t] [:div])
|
||||
@@ -115,44 +116,45 @@
|
||||
extract-fn :value
|
||||
extract-chosen-fn identity
|
||||
exact-match-exclude-items #{}
|
||||
initial-open? true}}]
|
||||
(let [input (::input state)
|
||||
initial-open? true
|
||||
clear-input-on-chosen? true}}]
|
||||
(let [*input (::input state)
|
||||
*toggle (::toggle state)
|
||||
*selected-choices (::selected-choices state)
|
||||
selected-choices (rum/react *selected-choices)
|
||||
full-choices (cond->>
|
||||
(remove nil? items)
|
||||
(seq @input)
|
||||
(seq @*input)
|
||||
(remove :clear?))
|
||||
search-result' (->>
|
||||
(cond-> (search/fuzzy-search full-choices @input :limit limit :extract-fn extract-fn)
|
||||
(cond-> (search/fuzzy-search full-choices @*input :limit limit :extract-fn extract-fn)
|
||||
(fn? transform-fn)
|
||||
(transform-fn @input))
|
||||
(transform-fn @*input))
|
||||
(remove nil?))
|
||||
exact-transform-fn (if new-case-sensitive? identity string/lower-case)
|
||||
exact-match? (contains? (set (map (comp exact-transform-fn str extract-fn) search-result'))
|
||||
(exact-transform-fn @input))
|
||||
search-result' (if (and multiple-choices? (not (string/blank? @input)))
|
||||
(exact-transform-fn @*input))
|
||||
search-result' (if (and multiple-choices? (not (string/blank? @*input)))
|
||||
(sort-by (fn [item]
|
||||
(not (contains? selected-choices (:value item))))
|
||||
search-result')
|
||||
search-result')
|
||||
search-result (if (and show-new-when-not-exact-match?
|
||||
(not exact-match?)
|
||||
(not (string/blank? @input))
|
||||
(not (exact-match-exclude-items @input)))
|
||||
(not (string/blank? @*input))
|
||||
(not (exact-match-exclude-items @*input)))
|
||||
(->>
|
||||
(cons
|
||||
(first search-result')
|
||||
(cons {:value @input
|
||||
:label (str "+ New option: " @input)}
|
||||
(cons {:value @*input
|
||||
:label (str "+ New option: " @*input)}
|
||||
(rest search-result')))
|
||||
(remove nil?))
|
||||
search-result')
|
||||
input-opts' (if (fn? input-opts) (input-opts (empty? search-result)) input-opts)
|
||||
input-container (or
|
||||
input-container
|
||||
(search-input input
|
||||
(search-input *input
|
||||
{:prompt-key prompt-key
|
||||
:input-default-placeholder input-default-placeholder
|
||||
:input-opts input-opts'
|
||||
@@ -171,7 +173,8 @@
|
||||
(render-item result chosen? multiple-choices? *selected-choices)))
|
||||
:class "cp__select-results"
|
||||
:on-chosen (fn [raw-chosen e]
|
||||
(reset! input "")
|
||||
(when clear-input-on-chosen?
|
||||
(reset! *input ""))
|
||||
(let [chosen (extract-chosen-fn raw-chosen)]
|
||||
(if multiple-choices?
|
||||
(if (selected-choices chosen)
|
||||
@@ -197,7 +200,7 @@
|
||||
(on-apply selected-choices)
|
||||
(when close-modal? (state/close-modal!)))})])]))]
|
||||
(when (fn? tap-*input-val)
|
||||
(tap-*input-val input))
|
||||
(tap-*input-val *input))
|
||||
[:div.cp__select
|
||||
(merge {:class "cp__select-main"}
|
||||
host-opts)
|
||||
|
||||
Reference in New Issue
Block a user