From bf5c68a58ba8e64f7b5248349d2fb2f92883207e Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Mon, 23 May 2016 17:34:44 +0300 Subject: [PATCH] More fixes on images. --- src/uxbox/data/images.cljs | 33 ++++++++++++++++-------------- src/uxbox/state/images.cljs | 4 +--- src/uxbox/ui/dashboard/images.cljs | 18 ++++++++-------- 3 files changed, 29 insertions(+), 26 deletions(-) diff --git a/src/uxbox/data/images.cljs b/src/uxbox/data/images.cljs index 8081099fe4..3753e59b05 100644 --- a/src/uxbox/data/images.cljs +++ b/src/uxbox/data/images.cljs @@ -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] diff --git a/src/uxbox/state/images.cljs b/src/uxbox/state/images.cljs index 1691c1dd71..9ebbdd2c95 100644 --- a/src/uxbox/state/images.cljs +++ b/src/uxbox/state/images.cljs @@ -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)) diff --git a/src/uxbox/ui/dashboard/images.cljs b/src/uxbox/ui/dashboard/images.cljs index a59d33c6ee..5e3ffceeb4 100644 --- a/src/uxbox/ui/dashboard/images.cljs +++ b/src/uxbox/ui/dashboard/images.cljs @@ -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)