mirror of
https://github.com/penpot/penpot.git
synced 2025-03-08 13:51:27 -05:00
Addapt images create event to support on-complete callback.
This commit is contained in:
parent
f17642f057
commit
997876db32
1 changed files with 19 additions and 6 deletions
|
@ -191,7 +191,11 @@
|
||||||
|
|
||||||
(def allowed-file-types #{"image/jpeg" "image/png"})
|
(def allowed-file-types #{"image/jpeg" "image/png"})
|
||||||
|
|
||||||
(defrecord CreateImages [id files]
|
(defrecord CreateImages [id files on-uploaded]
|
||||||
|
rs/UpdateEvent
|
||||||
|
(-apply-update [_ state]
|
||||||
|
(assoc-in state [:dashboard :images :uploading] true))
|
||||||
|
|
||||||
rs/WatchEvent
|
rs/WatchEvent
|
||||||
(-apply-watch [_ state s]
|
(-apply-watch [_ state s]
|
||||||
(letfn [(image-size [file]
|
(letfn [(image-size [file]
|
||||||
|
@ -199,6 +203,8 @@
|
||||||
(rx/map (partial vector file))))
|
(rx/map (partial vector file))))
|
||||||
(allowed-file? [file]
|
(allowed-file? [file]
|
||||||
(contains? allowed-file-types (.-type file)))
|
(contains? allowed-file-types (.-type file)))
|
||||||
|
(finalize-upload []
|
||||||
|
(assoc-in state [:dashboard :images :uploading] false))
|
||||||
(prepare [[file [width height]]]
|
(prepare [[file [width height]]]
|
||||||
{:collection id
|
{:collection id
|
||||||
:mimetype (.-type file)
|
:mimetype (.-type file)
|
||||||
|
@ -208,16 +214,23 @@
|
||||||
:height height})]
|
:height height})]
|
||||||
(->> (rx/from-coll (jscoll->vec files))
|
(->> (rx/from-coll (jscoll->vec files))
|
||||||
(rx/filter allowed-file?)
|
(rx/filter allowed-file?)
|
||||||
(rx/flat-map image-size)
|
(rx/mapcat image-size)
|
||||||
(rx/map prepare)
|
(rx/map prepare)
|
||||||
(rx/flat-map #(rp/req :create/image %))
|
(rx/mapcat #(rp/req :create/image %))
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
|
(rx/reduce conj [])
|
||||||
|
(rx/do #(rs/emit! finalize-upload))
|
||||||
|
(rx/do on-uploaded)
|
||||||
|
(rx/mapcat identity)
|
||||||
(rx/map image-created)))))
|
(rx/map image-created)))))
|
||||||
|
|
||||||
(defn create-images
|
(defn create-images
|
||||||
[id files]
|
([id files]
|
||||||
{:pre [(or (uuid? id) (nil? id))]}
|
{:pre [(or (uuid? id) (nil? id))]}
|
||||||
(CreateImages. id files))
|
(CreateImages. id files (constantly nil)))
|
||||||
|
([id files on-uploaded]
|
||||||
|
{:pre [(or (uuid? id) (nil? id)) (fn? on-uploaded)]}
|
||||||
|
(CreateImages. id files on-uploaded)))
|
||||||
|
|
||||||
;; --- Image Updated
|
;; --- Image Updated
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue