0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-16 01:31:22 -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? (defn collections-fetched?
[v] [v]
(instance? CollectionFetched v)) (instance? CollectionsFetched v))
;; --- Collection Updated ;; --- Collection Updated
@ -182,30 +182,30 @@
[coll-id files] [coll-id files]
(CreateImages. coll-id files)) (CreateImages. coll-id files))
;; --- Images Loaded ;; --- Images Fetched
(defrecord ImagesLoaded [coll-id items] (defrecord ImagesFetched [coll-id items]
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(assoc-in state [:images-by-id coll-id :images] (set items)))) (assoc-in state [:images-by-id coll-id :images] (set items))))
(defn images-loaded (defn images-fetched
[coll-id items] [coll-id items]
(ImagesLoaded. coll-id items)) (ImagesFetched. coll-id items))
;; --- Load Images ;; --- Load Images
(defrecord LoadImages [coll-id] (defrecord FetchImages [coll-id]
rs/WatchEvent rs/WatchEvent
(-apply-watch [_ state s] (-apply-watch [_ state s]
(let [params {:coll coll-id}] (let [params {:coll coll-id}]
(->> (rp/req :fetch/images params) (->> (rp/req :fetch/images params)
(rx/map :payload) (rx/map :payload)
(rx/map #(images-loaded coll-id %)))))) (rx/map #(images-fetched coll-id %))))))
(defn load-images (defn fetch-images
[coll-id] [coll-id]
(LoadImages. coll-id)) (FetchImages. coll-id))
;; --- Delete Images ;; --- Delete Images
@ -225,18 +225,21 @@
;; --- Set Collection ;; --- Set Collection
(defrecord SetCollection [id] (defrecord SetCollection [id builtin?]
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(assoc-in state [:dashboard :collection-id] id)) (assoc-in state [:dashboard :collection-id] id))
rs/WatchEvent rs/WatchEvent
(-apply-watch [_ state s] (-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 (defn set-collection
[id] [id builtin?]
(SetCollection. id)) (SetCollection. id builtin?))
;; --- Set Collection Type ;; --- Set Collection Type
@ -244,9 +247,9 @@
rs/WatchEvent rs/WatchEvent
(-apply-watch [_ state s] (-apply-watch [_ state s]
(if (= type :builtin) (if (= type :builtin)
(rx/of (set-collection 1)) (rx/of (set-collection 1 true))
(let [colls (sort-by :id (vals (:images-by-id state)))] (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 rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]

View file

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

View file

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