mirror of
https://github.com/penpot/penpot.git
synced 2025-02-09 00:28:20 -05:00
Move image collections state transformations functions into data ns.
This commit is contained in:
parent
fa98c544cc
commit
931042018e
2 changed files with 7 additions and 32 deletions
|
@ -11,7 +11,6 @@
|
||||||
[uuid.core :as uuid]
|
[uuid.core :as uuid]
|
||||||
[uxbox.rstore :as rs]
|
[uxbox.rstore :as rs]
|
||||||
[uxbox.state :as st]
|
[uxbox.state :as st]
|
||||||
[uxbox.state.images :as sti]
|
|
||||||
[uxbox.repo :as rp]))
|
[uxbox.repo :as rp]))
|
||||||
|
|
||||||
;; --- Initialize
|
;; --- Initialize
|
||||||
|
@ -46,7 +45,10 @@
|
||||||
(defrecord CollectionsFetched [items]
|
(defrecord CollectionsFetched [items]
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(reduce sti/assoc-collection state items)))
|
(reduce (fn [acc {:keys [id] :as item}]
|
||||||
|
(assoc-in acc [:images-by-id id] item))
|
||||||
|
state
|
||||||
|
items)))
|
||||||
|
|
||||||
(defn collections-fetched
|
(defn collections-fetched
|
||||||
[items]
|
[items]
|
||||||
|
@ -71,7 +73,7 @@
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(-> state
|
(-> state
|
||||||
(sti/assoc-collection 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))))
|
||||||
|
|
||||||
|
@ -143,7 +145,7 @@
|
||||||
(defrecord DeleteCollection [id]
|
(defrecord DeleteCollection [id]
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(sti/dissoc-collection state id))
|
(update state :images-by-id dissoc id))
|
||||||
|
|
||||||
rs/WatchEvent
|
rs/WatchEvent
|
||||||
(-apply-watch [_ state s]
|
(-apply-watch [_ state s]
|
||||||
|
@ -218,7 +220,7 @@
|
||||||
(defrecord DeleteImage [coll-id image]
|
(defrecord DeleteImage [coll-id image]
|
||||||
rs/UpdateEvent
|
rs/UpdateEvent
|
||||||
(-apply-update [_ state]
|
(-apply-update [_ state]
|
||||||
(sti/dissoc-image state coll-id image))
|
(update-in state [:images-by-id coll-id :images] disj image))
|
||||||
|
|
||||||
rs/WatchEvent
|
rs/WatchEvent
|
||||||
(-apply-watch [_ state s]
|
(-apply-watch [_ state s]
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
(ns uxbox.state.images)
|
|
||||||
|
|
||||||
(defn assoc-collection
|
|
||||||
"A reduce function for assoc the image collection
|
|
||||||
to the state map."
|
|
||||||
[state coll]
|
|
||||||
(let [id (:id coll)]
|
|
||||||
(assoc-in state [:images-by-id id] coll)))
|
|
||||||
|
|
||||||
(defn dissoc-collection
|
|
||||||
"A reduce function for dissoc the image collection
|
|
||||||
to the state map."
|
|
||||||
[state id]
|
|
||||||
(update state :images-by-id dissoc id))
|
|
||||||
|
|
||||||
(defn select-first-collection
|
|
||||||
"A reduce function for select the first image collection
|
|
||||||
to the state map."
|
|
||||||
[state]
|
|
||||||
(let [colls (sort-by :id (vals (:images-by-id state)))]
|
|
||||||
(assoc-in state [:dashboard :collection-id] (:id (first colls)))))
|
|
||||||
|
|
||||||
(defn dissoc-image
|
|
||||||
"A reduce function for dissoc the image collection
|
|
||||||
to the state map."
|
|
||||||
[state coll-id image]
|
|
||||||
(update-in state [:images-by-id coll-id :images] disj image))
|
|
Loading…
Add table
Reference in a new issue