0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-15 09:11:21 -05:00

More fixes on images.

This commit is contained in:
Andrey Antukh 2016-05-23 17:34:44 +03:00
parent a60fbca002
commit bf5c68a58b
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
3 changed files with 29 additions and 26 deletions

View file

@ -96,7 +96,7 @@
(defn collections-fetched?
[v]
(instance? CollectionFetched v))
(instance? CollectionsFetched v))
;; --- Collection Updated
@ -182,30 +182,30 @@
[coll-id files]
(CreateImages. coll-id files))
;; --- Images Loaded
;; --- Images Fetched
(defrecord ImagesLoaded [coll-id items]
(defrecord ImagesFetched [coll-id items]
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:images-by-id coll-id :images] (set items))))
(defn images-loaded
(defn images-fetched
[coll-id items]
(ImagesLoaded. coll-id items))
(ImagesFetched. coll-id items))
;; --- Load Images
(defrecord LoadImages [coll-id]
(defrecord FetchImages [coll-id]
rs/WatchEvent
(-apply-watch [_ state s]
(let [params {:coll coll-id}]
(->> (rp/req :fetch/images params)
(rx/map :payload)
(rx/map #(images-loaded coll-id %))))))
(rx/map #(images-fetched coll-id %))))))
(defn load-images
(defn fetch-images
[coll-id]
(LoadImages. coll-id))
(FetchImages. coll-id))
;; --- Delete Images
@ -225,18 +225,21 @@
;; --- Set Collection
(defrecord SetCollection [id]
(defrecord SetCollection [id builtin?]
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:dashboard :collection-id] id))
rs/WatchEvent
(-apply-watch [_ state s]
(rx/of (load-images id))))
(cond
builtin? (rx/empty)
(nil? id) (rx/empty)
:else (rx/of (fetch-images id)))))
(defn set-collection
[id]
(SetCollection. id))
[id builtin?]
(SetCollection. id builtin?))
;; --- Set Collection Type
@ -244,9 +247,9 @@
rs/WatchEvent
(-apply-watch [_ state s]
(if (= type :builtin)
(rx/of (set-collection 1))
(rx/of (set-collection 1 true))
(let [colls (sort-by :id (vals (:images-by-id state)))]
(rx/of (set-collection (:id (first colls)))))))
(rx/of (set-collection (:id (first colls)) false)))))
rs/UpdateEvent
(-apply-update [_ state]

View file

@ -24,6 +24,4 @@
"A reduce function for dissoc the image collection
to the state map."
[state coll-id image]
(let [images (get-in state [:images-by-id coll-id :images])
images (filterv #(not= (:id image) (:id %)) images)]
(assoc-in state [:images-by-id coll-id images] images)))
(update-in state [:images-by-id coll-id :images] disj image))

View file

@ -57,8 +57,7 @@
(l/focus-atom st/state)))
(def ^:private collections-by-id-l
(-> (comp (l/key :images-by-id)
(ul/merge library/+image-collections-by-id+))
(-> (l/key :images-by-id)
(l/focus-atom st/state)))
(def ^:private images-ordering-l
@ -126,17 +125,17 @@
(defn nav-render
[own]
(let [dashboard (rum/react dashboard-l)
collections-by-id (rum/react collections-by-id-l)
collid (:collection-id dashboard)
own? (= (:collection-type dashboard) :own)
builtin? (= (:collection-type dashboard) :builtin)
collections (cond->> (vals collections-by-id)
(true? own?) (filter (comp not :builtin))
(false? own?) (filter :builtin))
collections (if builtin?
(vals library/+image-collections-by-id+)
(rum/react collections-by-id-l))
show-builtin #(rs/emit! (di/set-collection-type :builtin))
show-own #(rs/emit! (di/set-collection-type :own))
new-coll #(rs/emit! (di/create-collection))
select-coll #(rs/emit! (di/set-collection %))]
select-coll #(rs/emit! (di/set-collection % builtin?))]
(html
[:div.library-bar
[:div.library-bar-inside
@ -175,7 +174,10 @@
coll-type (:collection-type dashboard)
coll-id (:collection-id dashboard)
own? (= coll-type :own)
coll (rum/react (focus-collection coll-id))
builtin? (= coll-type :builtin)
coll (if builtin?
(get library/+image-collections-by-id+ coll-id)
(rum/react (focus-collection coll-id)))
images-filtering (rum/react images-filtering-l)
images-ordering (rum/react images-ordering-l)
images (->> (:images coll)