Browse Source

feat(mobile): add priority toggle button to toolbar

leizhe 4 years ago
parent
commit
7a8aa9329c

+ 7 - 0
src/main/frontend/components/editor.cljs

@@ -318,6 +318,13 @@
                            (.focus input)))}
        (ui/icon "command"
                 {:style {:fontSize ui/icon-size}})]]
+     [:div
+      [:button.bottom-action
+       {:on-mouse-down (fn [e]
+                         (util/stop e)
+                         (editor-handler/cycle-priority!))}
+       (ui/icon "a-b"
+                {:style {:fontSize ui/icon-size}})]]
      [:div
       [:button.bottom-action
        {:on-mouse-down (fn [e]

+ 12 - 0
src/main/frontend/handler/editor.cljs

@@ -46,6 +46,7 @@
             [frontend.util.marker :as marker]
             [frontend.util.page-property :as page-property]
             [frontend.util.property :as property]
+            [frontend.util.priority :as priority]
             [frontend.util.thingatpt :as thingatpt]
             [frontend.util.list :as list]
             [goog.dom :as gdom]
@@ -915,6 +916,17 @@
                                           (util/format "[#%s]" new-priority))]
     (save-block-if-changed! block new-content)))
 
+(defn cycle-priority!
+  []
+  (when (state/get-edit-block)
+    (let [format (or (db/get-page-format (state/get-current-page))
+                     (state/get-preferred-format))
+          input-id (state/get-edit-input-id)
+          content (state/get-edit-content)
+          new-priority (priority/cycle-priority-state content)
+          new-value (priority/add-or-update-priority content format new-priority)]
+      (state/set-edit-content! input-id new-value))))
+
 (defn delete-block-aux!
   [{:block/keys [uuid repo] :as _block} children?]
   (let [repo (or repo (state/get-current-repo))

+ 14 - 0
src/main/frontend/util/priority.cljs

@@ -3,6 +3,20 @@
             [frontend.util :as util]
             [frontend.util.marker :as marker]))
 
+(defn cycle-priority-state
+  [content]
+  (let [priority-reg #"\[#(ABC){1}\]\s{1}"
+        priority (last (util/safe-re-find priority-reg content))
+        next-priority (case priority
+                        "A" "B"
+
+                        "B" "C"
+
+                        "C" nil
+
+                        "A")]
+    (and next-priority (util/format "[#%s]" next-priority))))
+
 (defn add-or-update-priority
   [content format priority]
   (let [priority-pattern  #"(\[#[ABC]\])?\s?"