Add missing fields on loaded image collections.

This commit is contained in:
Andrey Antukh 2016-09-24 21:17:43 +03:00
parent 6c43164ed1
commit abead1aa9e
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95

View file

@ -45,16 +45,33 @@
(rx/empty)))) (rx/empty))))
(defn initialize (defn initialize
[] [type id]
(Initialize.)) (Initialize. type id))
;; --- Select a Collection
(defrecord SelectCollection [type id]
rs/WatchEvent
(-apply-watch [_ state stream]
(rx/of (r/navigate :dashboard/images
{:type type :id id}))))
(defn select-collection
([type]
(select-collection type nil))
([type id]
{:pre [(keyword? type)]}
(SelectCollection. type id)))
;; --- Color Collections Fetched ;; --- Color Collections Fetched
(defrecord CollectionsFetched [items] (defrecord CollectionsFetched [items]
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(reduce (fn [acc {:keys [id] :as item}] (reduce (fn [state item]
(assoc-in acc [:images-by-id id] item)) (let [id (:id item)
item (assoc item :type :own)]
(assoc-in state [:images-by-id id] item)))
state state
items))) items)))
@ -80,10 +97,11 @@
(defrecord CollectionCreated [item] (defrecord CollectionCreated [item]
rs/UpdateEvent rs/UpdateEvent
(-apply-update [_ state] (-apply-update [_ state]
(let [item (assoc item :type :own)]
(-> state (-> state
(assoc-in [:images-by-id (:id item)] item) (assoc-in [:images-by-id (:id item)] item)
(assoc-in [:dashboard :collection-id] (:id item)) (assoc-in [:dashboard :collection-id] (:id item))
(assoc-in [:dashboard :collection-type] :own)))) (assoc-in [:dashboard :collection-type] :own)))))
(defn collection-created (defn collection-created
[item] [item]