Clean setTimeout

This commit is contained in:
Tienson Qin
2024-01-10 23:52:47 +08:00
parent 8533a974f1
commit 7600a53929
4 changed files with 30 additions and 28 deletions

View File

@@ -36,14 +36,13 @@
(let [repo (state/get-current-repo)
conn (db/get-db repo false)
config (state/get-config repo)]
(when-let [page-name (worker-page/create! repo conn config title options)]
(when redirect?
(route-handler/redirect-to-page! page-name))
(js/setTimeout
#(when-let [first-block (first (:block/_left (db/entity [:block/name page-name])))]
(block-handler/edit-block! first-block :max nil))
100)
page-name))))
(p/let [_ (worker-page/create! repo conn config title options)]
(let [[_ page-name] (worker-page/get-title-and-pagename title)]
(when redirect?
(route-handler/redirect-to-page! page-name))
(when-let [first-block (first (:block/_left (db/entity [:block/name page-name])))]
(block-handler/edit-block! first-block :max nil))
page-name)))))
;; favorite fns
;; ============

View File

@@ -21,9 +21,7 @@
(when content
(editor-handler/restore-cursor-pos! id content)))
;; Here we delay this listener, otherwise the click to edit event will trigger a outside click event,
;; which will hide the editor so no way for editing.
(js/setTimeout #(keyboards-handler/esc-save! state) 100)
(keyboards-handler/esc-save! state)
(when-let [element (gdom/getElement id)]
(.focus element)

View File

@@ -284,15 +284,15 @@
format (state/get-preferred-format repo)
template (state/get-default-journal-template)
create-f (fn []
(create! title {:redirect? false
:split-namespace? false
:create-first-block? (not template)
:journal? true
:today-journal? true})
(js/setTimeout #(do
(state/pub-event! [:journal/insert-template today-page])
(ui-handler/re-render-root!)
(plugin-handler/hook-plugin-app :today-journal-created {:title today-page})) 100))]
(p/do!
(create! title {:redirect? false
:split-namespace? false
:create-first-block? (not template)
:journal? true
:today-journal? true})
(state/pub-event! [:journal/insert-template today-page])
(ui-handler/re-render-root!)
(plugin-handler/hook-plugin-app :today-journal-created {:title today-page})))]
(when (db/page-empty? repo today-page)
(if (config/db-based-graph? repo)
(let [page-exists (db/get-page today-page)]