Minor improvement on how colors are rendered in colors library.

This commit is contained in:
Andrey Antukh 2016-01-11 22:28:56 +02:00
parent 0abc29451a
commit c8c2625082
2 changed files with 27 additions and 20 deletions

View file

@ -22,17 +22,19 @@
;; Lenses ;; Lenses
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(def ^:static dashboard-state (def ^:static ^:private dashboard-l
(as-> (l/in [:dashboard]) $ (-> (l/in [:dashboard])
(l/focus-atom $ st/state))) (l/focus-atom st/state)))
(def ^:static collections-state (def ^:static ^:private collections-by-id-l
(as-> (l/in [:colors-by-id]) $ (-> (comp (l/in [:colors-by-id])
(l/focus-atom $ st/state))) (ul/merge library/+color-collections-by-id+))
(l/focus-atom st/state)))
(def ^:static collection-state (defn- focus-collection
(as-> (ul/dep-in [:colors-by-id] [:dashboard :collection-id]) $ [collid]
(l/focus-atom $ st/state))) (-> (l/key collid)
(l/focus-atom collections-by-id-l)))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Page Title ;; Page Title
@ -46,7 +48,7 @@
(rs/emit! (dd/rename-color-collection collid content)))) (rs/emit! (dd/rename-color-collection collid content))))
(on-delete [e] (on-delete [e]
(rs/emit! (dd/delete-color-collection (:id coll))))] (rs/emit! (dd/delete-color-collection (:id coll))))]
(let [dashboard (rum/react dashboard-state) (let [dashboard (rum/react dashboard-l)
own? (:builtin coll false)] own? (:builtin coll false)]
(html (html
[:div.dashboard-title {} [:div.dashboard-title {}
@ -72,14 +74,15 @@
(defn nav-render (defn nav-render
[own] [own]
(let [dashboard (rum/react dashboard-state) (let [dashboard (rum/react dashboard-l)
colors (rum/react collections-state) 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 (if own? collections (as-> (vals collections-by-id) $
(sort-by :id (vals colors)) (if own?
library/+color-collections+)] (filter (comp not :builtin) $)
(filter :builtin $)))]
(html (html
[:div.library-bar [:div.library-bar
[:div.library-bar-inside [:div.library-bar-inside
@ -117,13 +120,11 @@
(defn grid-render (defn grid-render
[own] [own]
(let [dashboard (rum/react dashboard-state) (let [dashboard (rum/react dashboard-l)
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 (case coll-type coll (rum/react (focus-collection coll-id))
:builtin (get library/+color-collections-by-id+ coll-id)
:own (rum/react collection-state))
edit-cb #(lightbox/open! :color-form {:coll coll :color %}) edit-cb #(lightbox/open! :color-form {:coll coll :color %})
remove-cb #(rs/emit! (dd/remove-color {:id (:id coll) :color %}))] remove-cb #(rs/emit! (dd/remove-color {:id (:id coll) :color %}))]
(when coll (when coll

View file

@ -1,5 +1,5 @@
(ns uxbox.util.lens (ns uxbox.util.lens
(:refer-clojure :exclude [derive]) (:refer-clojure :exclude [derive merge])
(:require [cats.labs.lens :as l])) (:require [cats.labs.lens :as l]))
(defn dep-in (defn dep-in
@ -17,6 +17,12 @@
[f] [f]
(l/lens f #(throw (ex-info "Not implemented" {})))) (l/lens f #(throw (ex-info "Not implemented" {}))))
(defn merge
[data]
(l/lens
(fn [s] (cljs.core/merge s data))
#(throw (ex-info "Not implemented" {}))))
(defn derive (defn derive
[a path] [a path]
(l/focus-atom (l/in path) a)) (l/focus-atom (l/in path) a))