persist commands order on mobile

pull/4766/head
llcc 2022-04-01 18:51:41 +08:00 committed by Tienson Qin
parent 4df8459615
commit 35ce12ced2
1 changed files with 18 additions and 14 deletions

View File

@ -26,7 +26,8 @@
[goog.dom :as gdom] [goog.dom :as gdom]
[promesa.core :as p] [promesa.core :as p]
[rum.core :as rum] [rum.core :as rum]
[frontend.handler.history :as history])) [frontend.handler.history :as history]
[frontend.handler.config :as config-handler]))
(rum/defc commands < rum/reactive (rum/defc commands < rum/reactive
[id format] [id format]
@ -238,18 +239,21 @@
(ui/icon icon {:style {:fontSize ui/icon-size}})]]) (ui/icon icon {:style {:fontSize ui/icon-size}})]])
(def ^:private mobile-bar-icons-keywords (def ^:private mobile-bar-icons-keywords
[:checkbox :brackets :parentheses :command :tag :a-b :list :microphone :camera [:checkbox :brackets :parentheses :command :tag :a-b :list :camera
:brand-youtube :link :rotate :rotate-clockwise :code :bold :italic :strikethrough :paint]) :brand-youtube :link :rotate :rotate-clockwise :code :bold :italic :strikethrough :paint])
(def ^:private mobile-bar-commands-state (def ^:private mobile-bar-commands-stats
(atom (into {} (mapv (fn [name] [name {:counts 0}]) (atom (or (:mobile/toolbar-stats (state/get-config))
mobile-bar-icons-keywords)))) (into {} (mapv (fn [name] [name {:counts 0}])
mobile-bar-icons-keywords)))))
(defn set-command-state [icon] (defn set-command-stats [icon]
(let [key (keyword icon) (let [key (keyword icon)
counts (get-in @mobile-bar-commands-state [key :counts])] counts (get-in @mobile-bar-commands-stats [key :counts])]
(swap! mobile-bar-commands-state (swap! mobile-bar-commands-stats
assoc-in [key :counts] (inc counts)))) assoc-in [key :counts] (inc counts))
(config-handler/set-config!
:mobile/toolbar-stats @mobile-bar-commands-stats)))
(rum/defc mobile-bar-command (rum/defc mobile-bar-command
[command-handler icon & [count? event?]] [command-handler icon & [count? event?]]
@ -258,7 +262,7 @@
{:on-mouse-down (fn [e] {:on-mouse-down (fn [e]
(util/stop e) (util/stop e)
(when count? (when count?
(set-command-state icon)) (set-command-stats icon))
(if event? (if event?
(command-handler e) (command-handler e)
(command-handler)))} (command-handler)))}
@ -277,7 +281,6 @@
(mobile-bar-command #(do (viewport-fn) (commands/simple-insert! parent-id "#" {})) "tag" true) (mobile-bar-command #(do (viewport-fn) (commands/simple-insert! parent-id "#" {})) "tag" true)
(mobile-bar-command editor-handler/cycle-priority! "a-b" true) (mobile-bar-command editor-handler/cycle-priority! "a-b" true)
(mobile-bar-command editor-handler/toggle-list! "list" true) (mobile-bar-command editor-handler/toggle-list! "list" true)
(mobile-bar-command #(record/start-recording) "microphone" true)
(mobile-bar-command #(mobile-camera/embed-photo parent-id) "camera" true) (mobile-bar-command #(mobile-camera/embed-photo parent-id) "camera" true)
(mobile-bar-command commands/insert-youtube-timestamp "brand-youtube" true) (mobile-bar-command commands/insert-youtube-timestamp "brand-youtube" true)
(mobile-bar-command editor-handler/html-link-format! "link" true) (mobile-bar-command editor-handler/html-link-format! "link" true)
@ -293,7 +296,8 @@
[parent-state parent-id] [parent-state parent-id]
(let [vw-state (state/sub :ui/visual-viewport-state) (let [vw-state (state/sub :ui/visual-viewport-state)
vw-pending? (state/sub :ui/visual-viewport-pending?) vw-pending? (state/sub :ui/visual-viewport-pending?)
commands (mobile-bar-commands parent-state parent-id)] commands (mobile-bar-commands parent-state parent-id)
sorted-commands (sort-by (comp :counts second) > @mobile-bar-commands-stats)]
[:div#mobile-editor-toolbar.bg-base-2 [:div#mobile-editor-toolbar.bg-base-2
{:style {:bottom (if vw-state {:style {:bottom (if vw-state
(- (.-clientHeight js/document.documentElement) (- (.-clientHeight js/document.documentElement)
@ -307,8 +311,8 @@
(mobile-bar-command (editor-handler/move-up-down true) "arrow-bar-to-up") (mobile-bar-command (editor-handler/move-up-down true) "arrow-bar-to-up")
(mobile-bar-command (editor-handler/move-up-down false) "arrow-bar-to-down") (mobile-bar-command (editor-handler/move-up-down false) "arrow-bar-to-down")
(mobile-bar-command #(commands/simple-insert! parent-id "\n" {}) "arrow-back") (mobile-bar-command #(commands/simple-insert! parent-id "\n" {}) "arrow-back")
(for [command-key (sort-by val > @mobile-bar-commands-state)] (for [command sorted-commands]
((first command-key) commands))] ((first command) commands))]
[:div.toolbar-hide-keyboard [:div.toolbar-hide-keyboard
(mobile-bar-command #(state/clear-edit!) "keyboard-show")]])) (mobile-bar-command #(state/clear-edit!) "keyboard-show")]]))