From abead1aa9eb1a439fb4c60e86bfe7996b39c5ffe Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Sat, 24 Sep 2016 21:17:43 +0300 Subject: [PATCH] Add missing fields on loaded image collections. --- src/uxbox/main/data/images.cljs | 34 +++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/src/uxbox/main/data/images.cljs b/src/uxbox/main/data/images.cljs index 5aba4d4e1..ad32ffd3d 100644 --- a/src/uxbox/main/data/images.cljs +++ b/src/uxbox/main/data/images.cljs @@ -45,16 +45,33 @@ (rx/empty)))) (defn initialize - [] - (Initialize.)) + [type id] + (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 (defrecord CollectionsFetched [items] rs/UpdateEvent (-apply-update [_ state] - (reduce (fn [acc {:keys [id] :as item}] - (assoc-in acc [:images-by-id id] item)) + (reduce (fn [state item] + (let [id (:id item) + item (assoc item :type :own)] + (assoc-in state [:images-by-id id] item))) state items))) @@ -80,10 +97,11 @@ (defrecord CollectionCreated [item] rs/UpdateEvent (-apply-update [_ state] - (-> state - (assoc-in [:images-by-id (:id item)] item) - (assoc-in [:dashboard :collection-id] (:id item)) - (assoc-in [:dashboard :collection-type] :own)))) + (let [item (assoc item :type :own)] + (-> state + (assoc-in [:images-by-id (:id item)] item) + (assoc-in [:dashboard :collection-id] (:id item)) + (assoc-in [:dashboard :collection-type] :own))))) (defn collection-created [item]