|
13 | 13 | [frontend.handler.plugin :as plugin-handler] |
14 | 14 | [frontend.handler.plugin-config :as plugin-config-handler] |
15 | 15 | [frontend.handler.ui :as ui-handler] |
16 | | - [frontend.mixins :as mixins] |
17 | 16 | [frontend.rum :as rum-utils] |
18 | 17 | [frontend.search :as search] |
19 | 18 | [frontend.state :as state] |
|
30 | 29 |
|
31 | 30 | (def *dirties-toggle-items (atom {})) |
32 | 31 |
|
| 32 | +(defn- handle-installed-themes-key-down |
| 33 | + [*cursor *total ^js target ^js e] |
| 34 | + (case (.-keyCode e) |
| 35 | + 38 ;; up |
| 36 | + (do |
| 37 | + (util/stop e) |
| 38 | + (reset! *cursor |
| 39 | + (if (zero? @*cursor) |
| 40 | + (dec @*total) (dec @*cursor)))) |
| 41 | + 40 ;; down |
| 42 | + (do |
| 43 | + (util/stop e) |
| 44 | + (reset! *cursor |
| 45 | + (if (= @*cursor (dec @*total)) |
| 46 | + 0 (inc @*cursor)))) |
| 47 | + 13 ;; enter |
| 48 | + (do |
| 49 | + (util/stop e) |
| 50 | + (when-let [^js active (.querySelector target ".is-active")] |
| 51 | + (.click active))) |
| 52 | + nil)) |
| 53 | + |
33 | 54 | (defn- clear-dirties-states! |
34 | 55 | [] |
35 | 56 | (reset! *dirties-toggle-items {})) |
|
86 | 107 | (reset! *themes themes) |
87 | 108 | (reset! *total (count themes)) |
88 | 109 | state))} |
89 | | - (mixins/event-mixin |
90 | | - (fn [state] |
91 | | - (let [*cursor (::cursor state) |
92 | | - *total (::total state) |
93 | | - ^js target (rum/dom-node state)] |
94 | | - (.focus target) |
95 | | - (mixins/on-key-down |
96 | | - state {38 ;; up |
97 | | - (fn [^js _e] |
98 | | - (reset! *cursor |
99 | | - (if (zero? @*cursor) |
100 | | - (dec @*total) (dec @*cursor)))) |
101 | | - 40 ;; down |
102 | | - (fn [^js _e] |
103 | | - (reset! *cursor |
104 | | - (if (= @*cursor (dec @*total)) |
105 | | - 0 (inc @*cursor)))) |
106 | | - |
107 | | - 13 ;; enter |
108 | | - #(when-let [^js active (.querySelector target ".is-active")] |
109 | | - (.click active))})))) |
| 110 | + {:did-mount (fn [state] |
| 111 | + (some-> (rum/dom-node state) (.focus)) |
| 112 | + state)} |
110 | 113 | [state] |
111 | 114 | (let [*cursor (::cursor state) |
112 | | - *themes (::themes state)] |
| 115 | + *themes (::themes state) |
| 116 | + *total (::total state)] |
113 | 117 | [:div.cp__themes-installed |
114 | | - {:tab-index -1} |
| 118 | + {:tab-index -1 |
| 119 | + :on-key-down #(handle-installed-themes-key-down *cursor *total (.-currentTarget %) %)} |
115 | 120 | [:h1.mb-4.text-2xl.p-1 (t :nav/themes)] |
116 | 121 | (map-indexed |
117 | 122 | (fn [idx opt] |
|
0 commit comments