0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-01-10 08:50:57 -05:00

Improved image collection title edition behavior.

This commit is contained in:
Andrey Antukh 2016-05-24 00:14:52 +03:00
parent 38eb985c48
commit 96ca21277e
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -80,23 +80,28 @@
(let [local (:rum/local own) (let [local (:rum/local own)
dashboard (rum/react dashboard-l) dashboard (rum/react dashboard-l)
own? (:builtin coll false)] own? (:builtin coll false)]
(letfn [(on-title-save [e] (letfn [(persist [event]
(rs/emit! (di/rename-collection (:id coll) (:coll-name @local))) (let [name (:coll-name @local)]
(swap! local assoc :edit false)) (rs/emit! (di/rename-collection (:id coll) name))
(on-title-edited [e] (swap! local assoc :edit false)))
(on-key-down [event]
(cond (cond
(kbd/esc? e) (kbd/esc? event)
(swap! local assoc :edit false) (swap! local assoc :edit false)
(kbd/enter? e) (kbd/enter? event)
(do (dom/stop-propagation e) (do
(on-title-save e)) (dom/stop-propagation event)
(persist event))))
:else (on-input [event]
(let [content (dom/event->inner-text e)] (let [content (dom/event->inner-text event)]
(swap! local assoc :coll-name content)))) (swap! local assoc :coll-name content)))
(on-title-edit [e]
(on-edit [e]
(swap! local assoc :edit true :coll-name (:name coll))) (swap! local assoc :edit true :coll-name (:name coll)))
(on-delete [e] (on-delete [e]
(rs/emit! (di/delete-collection (:id coll))))] (rs/emit! (di/delete-collection (:id coll))))]
(html (html
@ -106,7 +111,8 @@
[:div.dashboard-title-field [:div.dashboard-title-field
[:span.edit [:span.edit
{:content-editable "" {:content-editable ""
:on-key-down on-title-edited} :on-input on-input
:on-key-down on-key-down}
(:name coll)] (:name coll)]
[:span.close [:span.close
{:on-click #(swap! local assoc :edit false)} {:on-click #(swap! local assoc :edit false)}
@ -116,8 +122,8 @@
(if (and (not own?) coll) (if (and (not own?) coll)
[:div.edition [:div.edition
(if (:edit @local) (if (:edit @local)
[:span {:on-click on-title-save} i/save] [:span {:on-click persist} i/save]
[:span {:on-click on-title-edit} i/pencil]) [:span {:on-click on-edit} i/pencil])
[:span {:on-click on-delete} i/trash]])])))) [:span {:on-click on-delete} i/trash]])]))))
(def ^:private page-title (def ^:private page-title