0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-03-12 07:41:43 -05:00

Many improvements to colors page.

This commit is contained in:
Andrey Antukh 2016-11-06 18:54:30 +01:00
parent dbaeb9d5f4
commit 7abfaf639e
No known key found for this signature in database
GPG key ID: 4DFEBCB8316A8B95
4 changed files with 25 additions and 25 deletions

View file

@ -3,7 +3,6 @@
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
;;
;; Copyright (c) 2015-2016 Andrey Antukh <niwi@niwi.nz>
;; Copyright (c) 2015-2016 Juan de la Cruz <delacruzgarciajuan@gmail.com>
(ns uxbox.main.data.colors
(:require [clojure.set :as set]
@ -61,9 +60,10 @@
(defrecord CollectionsFetched [data]
rs/UpdateEvent
(-apply-update [_ state]
(-> state
(assoc-in [:kvstore :color-collections] data)
(update :color-colls-by-id merge (:value data)))))
(let [{:keys [version value]} data]
(-> state
(update :color-collections merge value)
(assoc ::version version)))))
(defn collections-fetched
[data]
@ -81,11 +81,6 @@
(-apply-watch [_ state s]
(->> (rp/req :fetch/kvstore "color-collections")
(rx/map :payload)
(rx/map (fn [payload]
(if (nil? payload)
{:key "color-collections"
:value nil}
payload)))
(rx/map collections-fetched))))
(defn fetch-collections
@ -102,7 +97,7 @@
:created-at (dt/now)
:type :own
:colors #{}}]
(assoc-in state [:color-colls-by-id id] item)))
(assoc-in state [:color-collections id] item)))
rs/WatchEvent
(-apply-watch [_ state stream]
@ -121,10 +116,12 @@
(-apply-watch [_ state stream]
(let [builtin? #(= :builtin (:type %))
xform (remove (comp builtin? second))
value (->> (get state :color-colls-by-id)
version (get state ::version)
value (->> (get state :color-collections)
(into {} xform))
store (get-in state [:kvstore :color-collections])
store (assoc store :value value)]
store {:key "color-collections"
:version version
:value value}]
(->> (rp/req :update/kvstore store)
(rx/map :payload)
(rx/map collections-fetched)))))
@ -138,7 +135,7 @@
(defrecord RenameCollection [id name]
rs/UpdateEvent
(-apply-update [_ state]
(assoc-in state [:color-colls-by-id id :name] name))
(assoc-in state [:color-collections id :name] name))
rs/WatchEvent
(-apply-watch [_ state s]
@ -153,7 +150,7 @@
(defrecord DeleteCollection [id]
rs/UpdateEvent
(-apply-update [_ state]
(update state :color-colls-by-id dissoc id))
(update state :color-collections dissoc id))
rs/WatchEvent
(-apply-watch [_ state s]
@ -171,7 +168,7 @@
rs/UpdateEvent
(-apply-update [_ state]
(let [replacer #(-> (disj % from) (conj to))]
(update-in state [:color-colls-by-id id :colors] (fnil replacer #{}))))
(update-in state [:color-collections id :colors] (fnil replacer #{}))))
rs/WatchEvent
(-apply-watch [_ state s]
@ -187,7 +184,7 @@
(defrecord RemoveColors [id colors]
rs/UpdateEvent
(-apply-update [_ state]
(update-in state [:color-colls-by-id id :colors]
(update-in state [:color-collections id :colors]
#(set/difference % colors)))
rs/WatchEvent
@ -231,7 +228,7 @@
rs/UpdateEvent
(-apply-update [_ state]
(let [selected (get-in state [:dashboard :colors :selected])]
(update-in state [:color-colls-by-id id :colors] set/union selected)))
(update-in state [:color-collections id :colors] set/union selected)))
rs/WatchEvent
(-apply-watch [_ state stream]
@ -249,8 +246,8 @@
(-apply-update [_ state]
(let [selected (get-in state [:dashboard :colors :selected])]
(-> state
(update-in [:color-colls-by-id from :colors] set/difference selected)
(update-in [:color-colls-by-id to :colors] set/union selected))))
(update-in [:color-collections from :colors] set/difference selected)
(update-in [:color-collections to :colors] set/union selected))))
rs/WatchEvent
(-apply-watch [_ state stream]

View file

@ -15,11 +15,14 @@
[_ id]
(let [url (str url "/kvstore/" id)
params {:url url :method :get}]
(send! params)))
(->> (send! params)
(rx/map (fn [{:keys [payload] :as response}]
(if (nil? payload)
(assoc response :payload {:key id :value nil :version nil})
response))))))
(defmethod request :update/kvstore
[_ data]
(println ":update/kvstore" data)
(let [url (str url "/kvstore")
params {:url url :method :put :body data}]
(send! params)))

View file

@ -38,7 +38,7 @@
:icon-colls-by-id nil
:icons-by-id nil
:shapes-by-id nil
:color-colls-by-id colors/collections
:color-collections colors/collections
:projects-by-id nil
:pages-by-id nil})

View file

@ -33,7 +33,7 @@
(l/derive st/state)))
(def collections-ref
(-> (l/key :color-colls-by-id)
(-> (l/key :color-collections)
(l/derive st/state)))
;; --- Page Title
@ -105,7 +105,7 @@
(tr "ds.num-elements" (t/c colors))]])))
(def ^:private storage-num-colors-ref
(-> (comp (l/in [:color-colls-by-id nil :colors])
(-> (comp (l/in [:color-collections nil :colors])
(l/lens count))
(l/derive st/state)))