feat: cycle multiple todos

This commit is contained in:
Tienson Qin
2021-10-08 19:55:59 +08:00
parent d5578a2b22
commit baf6713316
3 changed files with 53 additions and 11 deletions

View File

@@ -837,9 +837,36 @@
(defn set-marker
[{:block/keys [uuid marker content format properties] :as block} new-marker]
(let [new-content (string/replace-first content (re-pattern (str "^" marker)) new-marker)]
(let [new-content (->
(if marker
(string/replace-first content (re-pattern (str "^" marker)) new-marker)
(str new-marker " " content))
(string/triml))]
(save-block-if-changed! block new-content)))
(defn- get-selected-blocks-with-children
[]
(when-let [blocks (seq (state/get-selection-blocks))]
(->> (mapcat (fn [block]
(cons block
(array-seq (dom/by-class block "ls-block"))))
blocks)
distinct)))
(defn cycle-todos!
[]
(when-let [blocks (seq (get-selected-blocks-with-children))]
(let [repo (state/get-current-repo)
workflow (state/get-preferred-workflow)
ids (->> (distinct (map #(when-let [id (dom/attr % "blockid")]
(uuid id)) blocks))
(remove nil?))]
(doseq [id ids]
(let [block (db/pull [:block/uuid id])
new-marker (marker/cycle-marker-state workflow (:block/marker block))
new-marker (if new-marker new-marker "")]
(set-marker block new-marker))))))
(defn set-priority
[{:block/keys [uuid marker priority content] :as block} new-priority]
(let [new-content (string/replace-first content
@@ -1052,15 +1079,6 @@
first)]
(state/exit-editing-and-set-selected-blocks! [block])))
(defn- get-selected-blocks-with-children
[]
(when-let [blocks (seq (state/get-selection-blocks))]
(->> (mapcat (fn [block]
(cons block
(array-seq (dom/by-class block "ls-block"))))
blocks)
distinct)))
(defn- blocks-with-level
[blocks]
(let [level-blocks (mapv #(assoc % :level 1) blocks)