0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-04-04 19:11:20 -05:00

Add copy and move tooltips to images page.

This commit is contained in:
Andrey Antukh 2016-10-23 17:21:46 +02:00
parent ae51454fc4
commit 81c75d953b
3 changed files with 144 additions and 8 deletions

View file

@ -219,6 +219,33 @@
{:pre [(or (uuid? id) (nil? id))]}
(CreateImages. id files))
;; --- Image Updated
(defrecord ImageUpdated [id data]
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:images-by-id id] data)))
(defn image-updated
[{:keys [id] :as data}]
{:pre [(map? data)]}
(ImageUpdated. id data))
;; --- Update Image
(defrecord UpdateImage [id]
rs/WatchEvent
(-apply-watch [_ state stream]
(let [image (get-in state [:images-by-id id])]
(->> (rp/req :update/image image)
(rx/map :payload)
(rx/map image-updated)))))
(defn update-image
[id]
{:pre [(uuid? id)]}
(UpdateImage. id))
;; --- Images Fetched
(defrecord ImagesFetched [items]
@ -323,10 +350,59 @@
(DeselectImage. id)
(SelectImage. id))))))
(defn deselect-image
[id]
{:pre [(uuid? id)]}
(DeselectImage. id))
(defn toggle-image-selection
[id]
(ToggleImageSelection. id))
;; --- Copy Selected Image
(defrecord CopySelected [id]
rs/WatchEvent
(-apply-watch [_ state stream]
(let [selected (get-in state [:dashboard :images :selected])
selected (map #(get-in state [:images-by-id %]) selected)]
(->> (rx/from-coll selected)
(rx/map #(dissoc % :id))
(rx/map #(assoc % :collection id))
(rx/flat-map #(rp/req :create/image %))
(rx/map :payload)
(rx/map image-created)))))
(defn copy-selected
[id]
{:pre [(or (uuid? id) (nil? id))]}
(CopySelected. id))
;; --- Move Selected Image
(defrecord MoveSelected [id]
rs/UpdateEvent
(-apply-update [_ state]
(let [selected (get-in state [:dashboard :images :selected])]
(reduce (fn [state image]
(assoc-in state [:images-by-id image :collection] id))
state
selected)))
rs/WatchEvent
(-apply-watch [_ state stream]
(let [selected (get-in state [:dashboard :images :selected])]
(rx/merge
(->> (rx/from-coll selected)
(rx/map update-image))
(->> (rx/from-coll selected)
(rx/map deselect-image))))))
(defn move-selected
[id]
{:pre [(or (uuid? id) (nil? id))]}
(MoveSelected. id))
;; --- Delete Selected
(defrecord DeleteSelected []

View file

@ -70,3 +70,10 @@
[_ id]
(let [url (str url "/library/images/" id)]
(send! {:url url :method :delete})))
(defmethod request :update/image
[_ {:keys [id collection] :as body}]
(let [params {:url (str url "/library/images/" id)
:method :put
:body body}]
(send! params)))

View file

@ -202,27 +202,80 @@
:type "file"
:on-change on-file-selected}]]))
(mx/defc grid-options
[{:keys [type] :as coll}]
(let [editable? (or (= type :own) (nil? coll))]
(mx/defc grid-options-copy
{:mixins [mx/reactive mx/static]}
[current-coll]
{:pre [(uuid? current-coll)]}
(let [colls (mx/react collections-ref)
colls (->> (vals colls)
(filter #(= :own (:type %)))
(remove #(= current-coll (:id %)))
(sort-by :name colls))
on-select (fn [event id]
(dom/prevent-default event)
(rs/emit! (di/copy-selected id)))]
[:ul.move-list
[:li.title "Copy to library"]
[:li [:a {:href "#" :on-click #(on-select % nil)} "Storage"]]
(for [coll colls
:let [id (:id coll)
name (:name coll)]]
[:li {:key (str id)}
[:a {:on-click #(on-select % id)} name]])]))
(mx/defc grid-options-move
{:mixins [mx/reactive mx/static]}
[current-coll]
{:pre [(uuid? current-coll)]}
(let [colls (mx/react collections-ref)
colls (->> (vals colls)
(filter #(= :own (:type %)))
(remove #(= current-coll (:id %)))
(sort-by :name colls))
on-select (fn [event id]
(println "on-select" event id)
(dom/prevent-default event)
(rs/emit! (di/move-selected id)))]
[:ul.move-list
[:li.title "Move to library"]
[:li [:a {:href "#" :on-click #(on-select % nil)} "Storage"]]
(for [coll colls
:let [id (:id coll)
name (:name coll)]]
[:li {:key (str id)}
[:a {:on-click #(on-select % id)} name]])]))
(mx/defcs grid-options
{:mixins [(mx/local) mx/static]}
[own {:keys [type id] :as coll}]
(let [editable? (or (= type :own) (nil? coll))
local (:rum/local own)]
(letfn [(delete []
(rs/emit! (di/delete-selected)))
(on-delete [event]
(udl/open! :confirm {:on-accept delete}))]
(udl/open! :confirm {:on-accept delete}))
(on-toggle-copy [event]
(swap! local update :show-copy-tooltip not))
(on-toggle-move [event]
(swap! local update :show-move-tooltip not))]
;; MULTISELECT OPTIONS BAR
[:div.multiselect-bar
(if editable?
[:div.multiselect-nav
#_[:span.move-item.tooltip.tooltip-top
{:alt "Move to"}
i/organize]
[:span.move-item.tooltip.tooltip-top
{:on-click on-toggle-move}
(when (:show-move-tooltip @local)
(grid-options-move id))
i/organize]
[:span.delete.tooltip.tooltip-top
{:alt "Delete"
:on-click on-delete}
i/trash]]
[:div.multiselect-nav
[:span.move-item.tooltip.tooltip-top
{:alt "Copy to"}
{:on-click on-toggle-copy}
(when (:show-copy-tooltip @local)
(grid-options-copy id))
i/organize]])])))
(mx/defc grid-item