fix: Datepicker behaves oddly if there are 2 datepickers visible at the same time (#7498)

fixes #7341

Co-authored-by: Gabriel Horner <97210743+logseq-cldwalker@users.noreply.github.com>
This commit is contained in:
sallto
2022-12-14 23:41:08 +01:00
committed by GitHub
parent 04b6bcf582
commit e96c3403bf
3 changed files with 40 additions and 26 deletions

View File

@@ -2082,39 +2082,29 @@
[:code "Property name begins with a non-numeric character and can contain alphanumeric characters and . * + ! - _ ? $ % & = < >. If -, + or . are the first character, the second character (if any) must be non-numeric."]]))
(rum/defcs timestamp-cp < rum/reactive
(rum/local false ::show?)
(rum/local {} ::pos)
{:will-unmount (fn [state]
(when-let [show? (::show? state)]
(reset! show? false))
state)}
[state block typ ast]
(let [show? (get state ::show?)]
[:div.flex.flex-col.timestamp
(let [ts-block (state/sub :editor/set-timestamp-block)
active? #(= (get block :block/uuid) (get-in ts-block [:block :block/uuid]))]
[:div.flex.flex-col.gap-4.timestamp
[:div.text-sm.flex.flex-row
[:div.opacity-50.font-medium.timestamp-label
(str typ ": ")]
[:a.opacity-80.hover:opacity-100
{:on-mouse-down (fn [e]
(util/stop e)
(if @show?
(if (active?)
(do
(reset! commands/*current-command nil)
(state/clear-editor-action!)
(state/set-timestamp-block! nil))
(do
(reset! show? false)
(reset! commands/*current-command nil)
(state/clear-editor-action!)
(state/set-timestamp-block! nil))
(do
(reset! show? true)
(reset! commands/*current-command typ)
(state/set-editor-action! :datepicker)
(state/set-timestamp-block! {:block block
:typ typ
:show? show?}))))}
:typ typ}))))}
[:span.time-start "<"] [:time (repeated/timestamp->text ast)] [:span.time-stop ">"]]]
(when (true? @show?)
(let [ts (repeated/timestamp->map ast)]
[:div.my-4
(datetime-comp/date-picker nil nil ts)]))]))
(when (active?)
(datetime-comp/date-picker nil nil (repeated/timestamp->map ast)))]))
(defn- target-forbidden-edit?
[target]