mirror of
https://github.com/penpot/penpot.git
synced 2025-02-03 12:59:12 -05:00
Refactor and adapt create-images event to backend changes.
This commit is contained in:
parent
ba8b20f8c0
commit
2b00395253
1 changed files with 15 additions and 9 deletions
|
@ -8,9 +8,12 @@
|
||||||
(ns uxbox.main.data.images
|
(ns uxbox.main.data.images
|
||||||
(:require [cuerdas.core :as str]
|
(:require [cuerdas.core :as str]
|
||||||
[beicon.core :as rx]
|
[beicon.core :as rx]
|
||||||
|
[promesa.core :as p]
|
||||||
|
[uxbox.util.data :refer (jscoll->vec)]
|
||||||
[uxbox.util.uuid :as uuid]
|
[uxbox.util.uuid :as uuid]
|
||||||
[uxbox.util.rstore :as rs]
|
[uxbox.util.rstore :as rs]
|
||||||
[uxbox.util.router :as r]
|
[uxbox.util.router :as r]
|
||||||
|
[uxbox.util.dom.files :as files]
|
||||||
[uxbox.main.state :as st]
|
[uxbox.main.state :as st]
|
||||||
[uxbox.main.repo :as rp]))
|
[uxbox.main.repo :as rp]))
|
||||||
|
|
||||||
|
@ -191,15 +194,18 @@
|
||||||
(defrecord CreateImages [coll-id files]
|
(defrecord CreateImages [coll-id files]
|
||||||
rs/WatchEvent
|
rs/WatchEvent
|
||||||
(-apply-watch [_ state s]
|
(-apply-watch [_ state s]
|
||||||
(let [files-to-array (fn [js-col]
|
(letfn [(image-size [file]
|
||||||
(-> (clj->js [])
|
(->> (files/get-image-size file)
|
||||||
(.-slice)
|
(rx/map (partial vector file))))
|
||||||
(.call js-col)
|
(prepare [[file [width height]]]
|
||||||
(js->clj)))
|
{:coll coll-id
|
||||||
images-data (map (fn [file] {:coll coll-id
|
|
||||||
:id (uuid/random)
|
:id (uuid/random)
|
||||||
:file file}) (files-to-array files))]
|
:file file
|
||||||
(->> (rx/from-coll images-data)
|
:width width
|
||||||
|
:height height})]
|
||||||
|
(->> (rx/from-coll (jscoll->vec files))
|
||||||
|
(rx/flat-map image-size)
|
||||||
|
(rx/map prepare)
|
||||||
(rx/flat-map #(rp/req :create/image %))
|
(rx/flat-map #(rp/req :create/image %))
|
||||||
(rx/map :payload)
|
(rx/map :payload)
|
||||||
(rx/map image-created)))))
|
(rx/map image-created)))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue